Java - Thing to know before proceed - Datatype Tutorial
There are 2 types of data types in Java: primitive datatype and non-primitive datatype.
Primitive Datatype- The datatype includes short, int, float, double, long, boolean, char, byte.
There are eight primitive data types supported by Java
- Boolean Data type
- It is used to store only two possible values: true and false.
- This data type is used to represent one bit of information.
- Its default value is false.
- Byte Data type
- It is a single 8-bit signed two's complement integer.
- Its value-range lies between -128 (-27 )to 127 (27 -1)(inclusive)
- Its default value is 0.
- Char Datatype
- It is a single 16-bit Unicode character.
- Its value-range lies between ‘\u0000’ (0) to ‘\uffff’ (65,535)(inclusive)
- Short Datatype
- It is a 16-bit signed two's complement integer.
- Its value-range lies between -32,768 (-215 )to 32,767 (215 -1)(inclusive)
- Its default value is 0.
- Int Datatype
- It is a 32-bit signed two's complement integer.
- Its value-range lies between - 2,147,483,648 (-231 )to 2,147,483,647 (231 -1)(inclusive)
- Its default value is 0.
- An integer is generally used as the default data type for integral values unless if there is no problem with memory.
- Float Datatype
- It is a single-precision 32-bit IEEE 754 floating point
- Its value-range is unlimited.
- Its default value is 0.0f
- Float is never used for precise value, it is used for decimal value, eg .currency
- Double Datatype
- It is a double-precision 64-bit IEEE 754 floating-point.
- Its value-range is unlimited
- It’s default value is 0.0d
- Double is also never used for precise value, it is used for decimal value, eg .currency
- Long Datatype
- It is a 64-bit signed two's complement integer.
- Its value-range lies between -9,223,372,036,854,775,808 (-263 )to 9,223,372,036,854,775,807 (263 -1)(inclusive)
- Its default value is 0L.
- Long is only used when a wider range value is needed.
Non-Primitive Datatype- The datatype includes Classes, Interfaces, and Array.