Java Keywords β All 50+ Reserved Words Explained
Java has 50+ reserved words you can't use as identifiers. They come in three groups: classic keywords, literals (true, false, null) and contextual keywords β modern additions like var, yield, record, sealed and permits that are only reserved in specific positions.
All keywords by category
| Category | Keywords |
|---|---|
| Access & visibility | public, private, protected |
| Class structure | class, interface, enum, recordβ , extends, implements, package, import |
| Modifiers | static, final, abstract, synchronized, native, transient, volatile, strictfp, sealedβ , non-sealedβ , permitsβ |
| Primitives | byte, short, int, long, float, double, boolean, char, void |
| Control flow | if, else, switch, case, default, for, while, do, break, continue, return, yieldβ |
| Exceptions | try, catch, finally, throw, throws |
| Object operations | new, this, super, instanceof |
| Type inference | varβ |
| Literals | true, false, null |
| Reserved, unused | goto, const |
β Contextual keyword β reserved only in specific syntactic positions.
The heavy hitters
Five keywords account for most Java code:
classβ defines a class.newβ creates an instance.thisβ refers to the current instance.staticβ attaches a member to the class instead of instances.finalβ assign-once variables, no-subclass classes, no-override methods.
Modifiers on modifiers
public static final int MAX = 100; // static + final = constant
private final Map<K,V> cache; // assigned in constructor
public abstract class Shape { ... } // can't be instantiated directly
public sealed interface Shape permits Circle, Square {} // Java 17+
Reserved but unused: goto and const
Both are reserved so they can't be used as identifiers, but Java doesn't implement them. Labelled break/continue replace most goto uses; static final replaces const.
All sub-topics
Common mistakes
- Using a keyword as an identifier β
int class = 5won't compile. Contextual keywords likevarandyieldcan be identifiers in non-reserved positions, but it's confusing β avoid it. - Forgetting
finalon constants βpublic static int MAXis a global mutable variable. Addfinal. - Confusing
finalwith immutability βfinal Listmeans you can't reassign the variable; you can still calllist.add().
Try it & related tools
Paste any snippet into the Java Beautifier to see all keywords highlighted, or run them in the Java Online Compiler.