The Type Zoo: int, long, double, boolean, char, String
Choosing types deliberately; the L suffix, char-vs-String quotes, and the sizes behind the ranges.
Java's primitive types are the raw values the CPU understands; everything else is an object.
| Type | Size | Range / use | Example |
|---|---|---|---|
| int | 32-bit | whole numbers ±~2.1 billion | int users = 1250; |
| long | 64-bit | whole numbers, huge counts, timestamps | long fileId = 9_876_543_210L; |
| double | 64-bit | decimals (default for floating point) | double price = 19.99; |
| float | 32-bit | decimals, rare; needs f suffix | float r = 0.5f; |
| boolean | — | true / false only | boolean active = true; |
| char | 16-bit | ONE character, single quotes | char grade = 'A'; |
| byte, short | 8/16-bit | memory-tight situations; rare for beginners | — |
Two details that bite everyone once:
longliterals need anLsuffix:9_876_543_210is anintliteral that does not fit, but9_876_543_210Lis fine. Underscores are just for readability.charuses single quotes,Stringdouble quotes:'A'is a 16-bit character,"A"is an object. They are different types entirely.
String is not primitive — it is a class:
String greeting = "hi"; // an object with methods
int len = greeting.length(); // 2
Everything in Java is typed, checked, and documented. When in doubt:
int for counting, double for measuring, boolean for deciding,
String for text, long when numbers get big.
Next: constants and the conversion rules between types.