Primarily we divide data types into 2 categories :
- Primitive
- Non Primitive
Datatype | Range | Size |
---|---|---|
boolean | true/false | Not defined |
char | 0 to 65,536 | 2 bytes |
byte | -128 to 127 | 1 byte |
short | -32,768 to 32,767 | 2 bytes |
int | -2,147,483,648 to 2,147,483, 647 | 4 bytes |
long | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | 8 bytes |
float | approx. ±3.40282347E+38F (6-7 significant decimal digits) | 4 bytes |
double | approx. ±1.79769313486231570E+308 (15 significant decimal digits) | 8 bytes |
Primitive datatypes are stored in the stack.
Everything other than above mentioned types are non primitive data types. Some of them are String, Array, etc.
The reference of a non primitive data type is stored in the stack and memory is allocated in heap. We'll discuss more about non-primitives later.