Primitive data types are built in data types. Primitive data types are also called as Basic data types.
Different Types differ in memory size and range of values.
|byte||1 byte||-128 to 127|
|short||2 bytes||-215 to (215)-1|
|int||4 bytes||-231 to (231)-1|
|long||8 bytes||-263 to (263)-1|
In java, only signed integers exist. Java does not have signed and unsigned keywords.
Unsigned values are not supported in Java
There are two decimal types supported in Java. Below table, shows details on the same.
|float||4 bytes||-3.7e-38 to 3.7e+38(Scientific notation)|
|double||8 bytes||-1.4e-308 to 1.4e+308|
NOTE:-3.7e-38 means -3.7 X 10 power of -38
Scientific notation is used to express very small or big values
How to declare and initialize float and double?
In C language 1 byte is used to store each character
ASCII(can represent only 255 different characters), and supports only English related characters
In Java 2 bytes are used to store each character. UNICODE is the code used to store characters in Java.
UNICODE Can represent 65,535 different characters.
Though UNICODE uses extra 1 byte, for each character, it supports most of the international characters directly, unlike ASCII code.
Java has built in support for internationalization(i18n)
boolean data type is used to represent only two values true or false. boolean uses 1 bit of storage
Above are eight primitive data types in Java.