Selasa, 26 Maret 2013

Differences Between Java and C#


A.    Java Primitive Types

1.        Logical --- boolean
Logical values are represented using the boolean type,which takes one of two values : true or false.
Example :
boolean result = true;
This example is to declare a variable which named by "result" as boolean datatype, and give it true value.

2.        Textual --- char
This type is representative by single unicode.
You must enclose a char literal in single quotes(' ').
Example :
 'a'  // The letter a
 '\t'  // A tab

3.        Integral --- byte, short, int, and long
 It using decimal, octal, and hexadecimal.
 byte = 8 bits
 short = 16 bits
 int = 32 bits
 long = 64 bits
Example :
 2 // decimal for integer 2
 077 // 0 indicates an octal value
 0xBAAC // 0x indicates a hexadecimal value

4.        Floating Points --- float and double
 "double" is the datatype default.
 E or e  ==> add exponential value
 F or f ==> float
 D or d ==> double
Example :
 3.14
 6.02E23 ==> 23 after E has a positive value, equivalent with 6.02E+23


B. C# Primitive Types


Because C# represents all primitive data types as objects, it is possible to call an object method on a primitive data type.
Example :
        static void Main()
{
    int i = 10;
    object o = i;
    System.Console.WriteLine(o.ToString());
}


>>  Type of Data Type
-  Value Types
They directly content data. The example are char, int, and float, which can be used for storing alphabets, integers, and floating point numbers.

-  Reference Type
They contain a reference to the variables which are stored in memory. The example is string datatype.

Differences between Java and C# :
-   To compare string values in Java, 
developers need to call the equals method on a string type 
as the == operator compares reference types by default. 
In C#, developers can use the == or != operators to compare string values directly.
-   Java's boolean is called bool in C#.
-   C# supports unsigned in addition to the signed integer types. 
-   Java does not feature unsigned integer types.


Tidak ada komentar:

Posting Komentar