Keywords in Java are reserved words that have a special, predefined meaning in the language and cannot be used as identifiers (like variable names, class names, or method names). There are around reserved words in Java, including standard keywords and a few “contextual” keywords that only act like keywords in specific situations.

What keywords are in Java?

Java keywords shape the language’s syntax and control things like data types, control flow, access levels, and object‑oriented features.

They are all lowercase (for example if, not If) and must be written exactly as defined by the language.

Main categories of keywords

Here’s a broader view of Java keywords grouped by what they do.

Data‑type keywords

These define the type of variables (numbers, characters, booleans, etc.).

  • boolean, char, byte, short, int, long, float, double

Control‑flow keywords

These decide which parts of the code run under what conditions.

  • if, else, switch, case, default, for, while, do, break, continue

Class, interface, and object‑oriented keywords

These enable classes, inheritance, and interfaces.

  • class, interface, record, enum, extends, implements, new, this, super, instanceof

Access and modifier keywords

These control visibility and behavior of classes, methods, and fields.

  • public, protected, private, static, final, abstract, synchronized, transient, volatile

Packages and imports

These organize code into modules and let you reuse code from other packages.

  • package, import

Exception‑handling keywords

These manage errors and exceptions in a controlled way.

  • try, catch, finally, throw, throws, assert

Special‑purpose and unused keywords

A few are reserved but not actively used in modern Java, plus a few “contextual” keywords that work only in specific contexts.

  • Not‑used: const, goto
  • Contextual: var, yield, record, sealed, non‑sealed

Sample table: Selected Java keywords

[10][4] [5][4] [3][4] [4][5] [5][4] [4][5]
Keyword Category Typical use
class Class / OOP Defines a new class.
public Access modifier Makes a class, method, or variable visible everywhere.
if Control flow Runs a block if a condition is true.
int Data type Declares a 32‑bit integer variable.
try / catch Exception handling Catches and handles exceptions.
static Modifier Belongs to the class, not an instance.

Quick note for beginners

If you ever try to name a variable class or int, the Java compiler will throw an error because these are keywords.

Knowing them helps you read Java code faster and also avoid naming mistakes in your own programs.

Information gathered from public forums or data available on the internet and portrayed here.