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

CategoryKeywords
Access & visibilitypublic, private, protected
Class structureclass, interface, enum, record†, extends, implements, package, import
Modifiersstatic, final, abstract, synchronized, native, transient, volatile, strictfp, sealed†, non-sealed†, permits†
Primitivesbyte, short, int, long, float, double, boolean, char, void
Control flowif, else, switch, case, default, for, while, do, break, continue, return, yield†
Exceptionstry, catch, finally, throw, throws
Object operationsnew, this, super, instanceof
Type inferencevar†
Literalstrue, false, null
Reserved, unusedgoto, 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 = 5 won't compile. Contextual keywords like var and yield can be identifiers in non-reserved positions, but it's confusing β€” avoid it.
  • Forgetting final on constants β€” public static int MAX is a global mutable variable. Add final.
  • Confusing final with immutability β€” final List means you can't reassign the variable; you can still call list.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.