Primitive Data Types in Java
Java has exactly eight primitive types, built directly into the language rather than being objects: byte, short, int, and long for whole numbers of increasing size; float and double for decimals; char for a single character; and boolean for true or false. Every primitive has a fixed bit width on every platform — int is always 32 bits, unlike C where int's size can vary by platform.
Primitives are stored directly rather than as a reference to an object elsewhere in memory, get a default value when used as a field (0, 0.0, false, and a null character for char), and each numeric type has a documented minimum and maximum. Going outside that range causes silent overflow rather than an error, which is a genuine practical gotcha worth knowing about early.
Integer family
byte (8-bit), short (16-bit), int (32-bit, the usual default), and long (64-bit, needs an L suffix on its literals).
Floating-point family
float (32-bit, needs an f suffix) and double (64-bit, the default type for any decimal literal).
Character type
char holds exactly one 16-bit Unicode character, written in single quotes.
Boolean type
Exactly two values, true and false, with no numeric stand-in — unlike C, 0 and 1 are not booleans in Java.
Fixed sizes everywhere
Every primitive's bit width is guaranteed identical on every platform, which is part of what keeps write-once-run-anywhere true at the data level too.
Overflow, not an error
Exceeding a type's range wraps silently around to the opposite end instead of throwing an exception, which is a common source of subtle bugs.
public class Primitives { public static void main(String[] args) { byte small = 127; int normal = 2147483647; int overflowed = normal + 1; System.out.println("byte: " + small); System.out.println("max int + 1 = " + overflowed); }}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in Java yourself — building beats watching.