Primitive Data Types

Java has eight built-in (primitive) types. They are stored by value, not by reference, and always default-initialise to the values shown in the last column. The fixed sizes are part of the language specification — an int is 32 bits on every JVM, regardless of the underlying hardware. This is one of the cornerstones of Java's “Write Once, Run Anywhere” promise: the same bytecode produces identical arithmetic on a 64-bit ARM Mac, an x86 Linux server, and a Raspberry Pi.

The eight types split into four integer types (byte, short, int, long), two floating-point types (float, double), one character type (char), and one boolean type. Java has no unsigned integer types — all integer types are signed two's complement. If you need unsigned arithmetic, use Integer.divideUnsigned and friends added in Java 8.

For monetary calculations or any case where decimal precision matters, do not use double — it cannot represent 0.1 exactly. Use BigDecimal instead, or store the value as integer cents. For most other purposes — counters, sizes, indices, time values in nanoseconds — int and long are the right choices.

TypeDescriptionRangeDefault
byte8-bit signed integer-128 to 1270
short16-bit signed integer-32,768 to 32,7670
int32-bit signed integer-2^31 to 2^31-10
long64-bit signed integer-2^63 to 2^63-10L
float32-bit IEEE 754 float~±3.4e380.0f
double64-bit IEEE 754 double~±1.7e3080.0d
char16-bit Unicode character\u0000 to \uFFFF\u0000
booleantrue / falsetrue, falsefalse

Java Keywords

Reserved words that you cannot use as identifiers. true, false and null are technically literals but treated as reserved. The list has grown slowly over Java's history: enum and assert were added in Java 5, var in Java 10 (as a contextual keyword, not strictly reserved), record, yield, sealed and permits more recently. The two unused keywords goto and const are reserved but generate a compile error if used — they were reserved in 1995 in case Java wanted them later, but the language designers chose not to.

If you ever need to know whether a given word is a keyword, the simplest test is to try using it as a variable name in a small program — if the compiler complains, it is reserved. IDEs will also colour reserved words differently from identifiers, which is the practical test most developers use day-to-day.

abstract assert boolean break byte case catch char class const continue default do double else enum extends final finally float for goto if implements import instanceof int interface long native new package private protected public return short static strictfp super switch synchronized this throw throws transient try void volatile while var record yield sealed permits true false null

Access Modifiers

Java provides four visibility levels, controlled by the four access modifiers: public, protected, the default package-private (no modifier), and private. The table below shows what each level makes visible to which audiences. The four audiences, from narrowest to widest, are: the same class, the same package, a subclass in a different package, and the world.

The general principle for healthy Java design is “least visibility”. Start with private for every field and helper method. Widen to package-private only when another class in the same package genuinely needs to call the method directly. Widen to protected only when you are designing for subclassing. Reserve public for the external contract of your package — the methods and classes you are willing to support across future versions.

ModifierClassPackageSubclassWorld
publicYYYY
protectedYYYN
(default)YYNN
privateYNNN

Operator Precedence (high to low)

Operator precedence determines how expressions group in the absence of parentheses. a + b * c groups as a + (b * c) because multiplication has higher precedence than addition. When two operators have the same precedence, associativity decides the grouping: most operators are left-associative, so a - b - c groups as (a - b) - c; assignment and the ternary are right-associative, so a = b = c groups as a = (b = c).

You should never rely on precedence alone for non-trivial expressions. When in doubt, add parentheses. (a + b) * c is universally understood; a + b * c forces the reader to recall precedence. The next reader — or you in six months — will thank you for the parentheses.

The table below shows the full precedence ladder from highest (level 1) to lowest (level 14). It is rare to need anything below level 7 in everyday code; bitwise and shift operators are mostly used in low-level work like hashing, encoding, and bit-packing.

LevelOperatorsAssociativity
1() [] . ::left
2++ -- + - ! ~ (cast) newright
3* / %left
4+ -left
5<< >> >>>left
6< <= > >= instanceofleft
7== !=left
8&left
9^left
10|left
11&&left
12||left
13?: (ternary)right
14= += -= *= /= %= &= ^= |= <<= >>= >>>=right

How to use this reference page

The most common use for this page is to remind yourself of a detail you have forgotten — the default value of a boolean field, or whether & is higher precedence than ^. Bookmark it in your browser so a single keystroke brings it up while you are coding.

If you are studying for a Java certification exam (Oracle Certified Associate or Professional), the keyword list and the access modifier table are guaranteed to appear on the test. Memorise both. The precedence table is less likely to be tested directly, but understanding it helps with reading other people's code.

For deeper treatments of any of these topics, click through to the relevant tutorial: data types, classes (for access modifiers), or operators. The reference page is a lookup; the tutorials are the explanations.

Reference

For more, see the official Java SE Documentation. Most rules apply equally to JDK 8, 11, 17 and 21.