Friday, 26 June 2015

DATATYPE AND WRAPPER CLASS

JAVA supports 8 primitive datatypes, then the language is not purely object oriented.
For each datatype. JAVA provides a predefined class ( known as wrapper class in JAVA).
Wrapper class is used to make JAVA pure object oriented.

All the wrapper class present in java.lang package and the default package in JAVA.

PRIMITIVE DATATYPE

Datatype.    Size.    default value.    Wrapper class
Byte.             8 Bits.           0.                    Byte
Short.            16 Bits.        0.                    Short      
Int.                 32 Bits.         0                    Integer
Long.             64 Bits.          0L.                Long
Float.             32 Bits.          0.0f.             Float
Double.          64 Bits.         0.0.                Double
Boolean.         1 Bit.             False.           Boolean
Char.               16 Bits.        /u0000.         Character

Wrapper class makes JAVA pure object oriented but still it's not purely object oriented ad it supports primitive datatypes.

Signed and unsigned are the two keywords that are not available in JAVA. So by default the datatype is signed in nature. Character datatype in JAVA is signed in nature, I.e it only holds positive value. (As ASCII value us always positive)

Negative number is always stored in the form of 2's complement. Example: 11111111 -> 00000001(2's complement) = -1.

MAX_VALUE & MIN_VALUE are the two predefined static constants which always display the maximum and the minimum value related to the datatype and present in each wrapper class.

toString ( ) is a predefined static method present in the wrapper class which converts any datatype to the string format.
parseByte( ) is a static method present in the Byte upper class which converts a string to byte datatype.