The 8 primitive types in Java
byte, short, int, long, float, double, char, boolean and their sizes.
Meet the eight
These are Java's primitive types: simple values, not objects. Everything else (String, arrays, your own classes) is a reference type, which you'll meet soon.
byte short int long // whole numbers
float double // decimals
char // one character
boolean // true / falseWhole numbers, doubling sizes
A bit is a single 0 or 1. byte uses 8 bits, short 16, int 32, long 64: each size doubles. int is the everyday default; long is for values beyond about ±2.1 billion.
byte 8 bits
short 16 bits
int 32 bits
long 64 bitsDecimals, chars, booleans
float is 32 bits and double is 64 bits (the default for decimals). char is 16 bits and holds one UTF-16 character unit; it's unsigned, from 0 to 65,535. boolean is simply true or false.
Odd one out
byte, int, char, String. Which one is not a primitive type?
Think about it, then reveal the answer
String. It's a class, so a String variable holds a reference to an object. All eight primitive type names are lowercase.
Your turn
Which 16-bit type can never hold a negative number?
shortchar
Show the answer
char, Java's only unsigned primitive. It stores UTF-16 code units, which are numbered from 0 upward. short is also 16 bits, but signed: −32,768 to 32,767.
Coming from C?
In C, an int might be 16, 32 or 64 bits depending on the machine. Java fixes every primitive's size in the language specification: an int is always 32 bits, on every CPU and every OS. That's part of what makes Java portable.
In real projects
Type choice is a memory decision at scale. An array of 10 million int values takes about 40 MB; the same in long takes about 80 MB. Databases, games and network protocols pick types to fit their data.
Key takeaways
- Integers: byte 8, short 16, int 32, long 64 bits
- Floating point: float 32, double 64 bits
- char: 16-bit unsigned; boolean: true/false
- Sizes never depend on the CPU or OS
The spec doesn't fix a size for boolean. JVM instructions treat booleans as ints (0 or 1), and Oracle's JVM stores boolean arrays using one byte per element.
Practice questions
Which one is NOT a primitive type?
- int
- String
- boolean
- char
Check your answer
String. String is a class, so a String variable holds a reference to an object. The other three are primitives.
Which primitive type is 16 bits and can never be negative?
- short
- char
- byte
- boolean
Check your answer
char. char is Java's only unsigned primitive, ranging from 0 to 65,535. short is also 16 bits but signed.