As previously mentioned, every variable in Java must have a defined data type.
int float char boolean String |
Data types are categorized into two groups:
Primitive data types – comprise byte, short, int, long, float, double, boolean, and char.Primitive data types in Java define the size and type of variable values and do not possess additional methods.
Java encompasses eight primitive data types:
Data Type |
Size |
Description |
|
1 byte |
Stores integers ranging from -128 to 127 |
|
2 bytes |
Stores integers ranging from – 32,768 to 32,767 |
|
4 bytes |
Stores integers ranging from – 2,147,483,648 to 2,147,483,647 |
|
8 bytes |
Stores integers ranging from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
|
4 bytes |
Stores fractional numbers with accuracy up to 6 to 7 decimal digits |
|
8 bytes |
Stores fractional numbers with precision up to 15 decimal digits |
|
1 bit |
Store values representing true or false |
|
2 bytes |
Stores a single character or ASCII values |