What Are The Keywords In Java

4 min read

Keywords in Java are the fixed, reserved words that the compiler recognizes as part of the language itself—words like class, public, static, if, and return that carry a specific meaning and cannot be reused as names for your variables, methods, or classes. Understanding what these keywords are, what they do, and how they differ from identifiers and literals is one of the first real milestones in learning Java, because almost every line of code you write depends on them.

What Are Keywords in Java?

In Java, a keyword is a predefined word that has a special, reserved meaning inside the compiler. Worth adding: you cannot use a keyword as an identifier—meaning you cannot name a variable int, a method class, or a class static. The compiler will reject it immediately with an error such as not a statement or <identifier> expected.

Java currently defines 50 reserved keywords, plus a small set of reserved literals (true, false, null) and one reserved underscore character (_). These words form the grammar of the language: they define how classes are declared, how access is controlled, how loops run, how exceptions are handled, and how memory and threads behave.

A simple example shows several keywords working together:

public class Hello {
    private static final int LIMIT = 10;

    public static void main(String[] args) {
        for (int i = 0; i < LIMIT; i++) {
            if (i % 2 == 0) {
                System.out.println(i);
            }
        }
    }
}

In those few lines you already meet public, class, private, static, final, int, void, for, if, and new (hidden inside array creation). That density is why keywords matter so much: they are the skeleton on which all Java logic hangs The details matter here..

The Complete List of Java Keywords

The 50 keywords are easier to remember when grouped by purpose rather than memorized alphabetically. Here is the full list organized by category.

Access Modifiers

  • public — visible to all classes.
  • private — visible only within the declaring class.
  • protected — visible within the package and to subclasses.
  • default — used in two ways: as package-private access (implicit) and inside switch statements.

Class, Interface, and Object Keywords

  • class, interface, enum — declare reference types.
  • extends — inherit from a class or interface.
  • implements — implement an interface.
  • new — create an object or array.
  • this — refer to the current object.
  • super — refer to the parent class.
  • instanceof — test an object's runtime type.
  • package, import — organize and reference code across namespaces.

Data Type Keywords

  • byte, short, int, long, float, double, char, boolean — the eight primitive types.
  • void — indicates a method returns nothing.

Control Flow Keywords

  • if, else — conditional branching.
  • switch, case — multi-way branching.
  • for, while, do — loops.
  • break, continue — loop control.
  • return — exit a method and optionally pass a value.

Exception Handling Keywords

  • try, catch, finally — the exception-handling block structure.
  • throw — raise an exception manually.
  • throws — declare exceptions a method may propagate.
  • assert — enable developer-level sanity checks.

Modifier and Concurrency Keywords

  • static — belongs to the class rather than an instance.
  • final — cannot be changed, overridden, or extended.
  • abstract — incomplete; must be implemented by a subclass.
  • synchronized — locks a method or block for thread safety.
  • volatile — forces reads and writes to go to main memory.
  • transient — excludes a field from serialization.
  • native — implemented in platform-specific code.
  • strictfp — enforces strict floating-point behavior.

Reserved but Unused Keywords

  • const and goto are reserved but have no function in Java. They exist so that code from C and C++ cannot accidentally compile as valid Java.

Keywords vs. Identifiers vs. Literals

Beginners often confuse these three concepts, so it helps to separate them clearly.

  • Keywords are reserved by the language and cannot be redefined.
  • Identifiers are the names you invent: variable names, method names, class names. They must start with a letter, $, or _, and cannot match any keyword.
  • Literals are fixed values written directly in code, such as 42, "hello", or 3.14.

The words true, false, and null are technically reserved literals, not keywords, though most tutorials list them together. Similarly, the single underscore _ became a reserved word in Java 9 and can no longer be used as an identifier That's the whole idea..

Contextual Keywords: The Modern Additions

Since Java 10, the language has introduced words

Out the Door

What's New

Worth Exploring Next

On a Similar Note

Thank you for reading about What Are The Keywords In Java. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home