JAVA
Not everything in Java is an object. There is a special group of data types (also known as primitive types)
that will be used quite often in your programming. For performance reasons, the designers of the Java language
decided to include these primitive types.
Creating an object using new isn't very efficient because new will place objects on the heap. This approach would be very costly for small and simple variables. Instead of create variables using new, Java can use primitive types to create automatic variables that are not references. The variables hold the value, and it's place on the stack so its much more efficient.
Java determines the size of each primitive type. These sizes do not change from one machine architecture to another (as do in most other languages). This is one of the key features of the language that makes Java so portable.
Take note that all numeric types are signed. (No unsigned types).
Finally, notice that each primitive data type also has a "wrapper" class defined for it. This means that you can create a "nonprimitive object" (using the wrapper class) on the heap (just like any other object) to represent the particular primitive type.
For example:int i = 5; Integer I = new Integer(i);ORInteger I = new Integer(5);
Data Types and Data Structures
Primitive Type | Size | Minimum Value | Maximum Value | Wrapper Type |
char | 16-bit | Unicode 0 | Unicode 216-1 | Character |
byte | 8-bit | -128 | +127 | Byte |
short | 16-bit | -215 (-32,768) |
+215-1 (32,767) |
Short |
int | 32-bit | -231 (-2,147,483,648) |
+231-1 (2,147,483,647) |
Integer |
long | 64-bit | -263 (-9,223,372,036,854,775,808) |
+263-1 (9,223,372,036,854,775,807) |
Long |
float | 32-bit | 32-bit IEEE 754 floating-point numbers | Float | |
double | 64-bit | 64-bit IEEE 754 floating-point numbers | Double | |
boolean | 1-bit | true or false | Boolean | |
void | ----- | ----- | ----- | Void |
C#
C# represents all primitive data types as objects, it is possible to call an object method on a primitive data type.
For example:
static void Main(){int i = 10;object o = i;System.Console.WriteLine(o.ToString());}C# PRIMITIVE TYPEFCL DATA TYPEDESCRIPTIONobjectSystem.ObjectUltimate base type of all other types.stringSystem.StringA sequence of Unicodecharacters.decimalSystem.DecimalPrecise decimal with 28 significant digits.boolSystem.BooleanA value represented as true or false.charSystem.CharA 16-bit Unicode character.byteSystem.Byte8-bit unsigned integral type.sbyteSystem.SByte8-bit signed integral type.shortSystem.Int1616-bit signed integral type.intSystem.Int3232-bit signed integral type.System.Int6464-bit signed integral type.ushortSystem.UInt1616-bit unsigned integral type.uintSystem.UInt3232-bit unsigned integral type.ulongSystem.UIint6464-bit unsigned integral type.single (float)System.SingleSingle-precision floating-point type.doubleSystem.DoubleDouble-precision floating-point type.
Tidak ada komentar:
Posting Komentar