October 2, 2009

Primitive Data-types

Primitive Data types :
Primitive data types are those data types that represent the data and are predefined by the language. They are named by a reserved keyword like int , char, byte etc..In total there are 8 primitive data types in Java. The size and range of each of them is shown in below table. [Click on the image to view in large form clearly]


Very simple formula to learn the ranges of any primitive datatype is just remember following formula
if bits is the no of bits of a particular primitive datatype
Minimum/negative range is -2 ^(bits-1)
Maximum/positive range is (2 ^(bits-1)) -1

So if size of byte is 8 bits then minimum range is -27 and maximum range is 27 -1.
[ Note : There is no range for a boolean type, a boolean can be true or false. So if anyone asks you what is the bit-depth of a boolean, just tell "That's virtual-machine dependent". ]


Each of these primitive data-types are preassigned a default value if no value is assigned to them at the time of declaration.Below is the table showing the list of default values of all primitive data-types.