In this post, you will learn the different primitive data types in Java programming languages.
Primitive data types in Java include the following:
boolean, byte, char, double, float, int, long, short
The above mentioned data types can be grouped into three categories:
Numeric type: it can store or hold numeric value or data (byte, double, float, int, long, short). These data types are usually used for mathematical functions or operations.
Textual/String type: it can store alphanumeric (characters and numbers or combination of both)
(char)
Boolean type: boolean (true and false)
The 8 primitive data types in Java:
boolean
storage size: 1 bit
value: true or false
default value: false
byte
storage size: 8 bit
range: -128 to 127
default value: 0
char
storage size: 16 bit
range: 0 to 65,535
default value: \u0000
double
storage size: 64 bit
range: 4.94065645841246544e-324d to 1.79769313486231570e+308d (positive or negative)
default value: 0.0
float
storage size: 32 bit
range: 0 to 3.402,823,5 E+38 to 1.4 E-45
default value: 0.0f
int
storage size: 32 bit
range: −2,147,483,648 to 2,147,483,647
default value: 0
long
storage size: 64 bit
range: 9,223,372,036,854,775,807 to -9,223,372,036,854,775,808
default value: 0
short
storage size: 16 bit
range: 32,767 to -32,768
default value: 0
Every variable in Java must have its proper data type, since variable can contain a value, a proper data type must be assign to a variable to save memory and to avoid errors.