Data Type | Size | Primitive/Reference | Value |
---|---|---|---|
boolean | 1 bit | primitive | true or false |
byte | 1 byte | primitive | -128 to 127 |
short | 2 bytes | primitive | -32,768 to 32,767 |
int | 4 bytes | primitive | -2 billion to 2 billion |
long | 8 bytes | primitive | -9 quintillion to 9 quintillion |
float | 4 bytes | primitive | fractional number up to 6-7 digits (e.g., 3.141592f) |
double | 8 bytes | primitive | fractional number up to 15 digits (e.g., 3.141592653589793) |
char | 2 bytes | primitive | single character/letter/ASCII value (e.g., ‘f’) |
String | varies | reference | a sequence of characters (e.g., “Hello world!“) |
Note
If u need to assign value to
float
data type u need to addf
at end of the number, but not in double
Primitive vs Reference Data Types
Transclude of Drawing-2024-08-28-03.41.15.excalidraw