In Java, a primitive data type is the most basic type of data that stores simple values directly in memory. They are not objects and are used to represent fundamental values like numbers, characters, or boolean states.
Java has 8 primitive data types:
byte
short
int
long
float
double
char
boolean
byte:
Size: 1 byte
Use: stores small integers (-128 to 127)short:
Size: 2 bytes
Use: stores medium integers
(-32,768 to 32,767)int:
Size: 4 bytes
Use: standard integer
(-2³¹ to 2³¹-1)
Minimum value = -2³¹ = -2,147,483,648
Maximum value = 2³¹ - 1 = 2,147,483,647long:
Size: 8 bytes
Use: large integer
(-2⁶³ to 2⁶³-1)
Minimum value = -2⁶³ = -9,223,372,036,854,775,808
*Maximum value *= 2⁶³ - 1 = 9,223,372,036,854,775,807float:
Size: 4 bytes
Use: decimal number
(single precision)double:
Size: 8 bytes
Use: decimal number
(double precision)char:
Size: 2 bytes
Use: single Unicode characterboolean:
stores true or false
Top comments (0)