Java Fundamentals  «Prev 

Java Keywords

This page supports the two keyword tables below by explaining what the keywords do, how they group together conceptually, and how modern Java (17 → 25) uses them in real code. The actual list of reserved keywords has been stable across Java 17 through Java 25; what’s changed is how you use them, e.g., pattern matching with instanceof, modern switch expressions, records, and sealed hierarchies.

How to read the tables

  1. Reserved words vs. literals: true, false, and null are literals (not operators or identifiers). const and goto are reserved but unused.
  2. No new keywords (17 → 25): The tables remain valid. New Java capabilities arrived mostly via features/APIs rather than adding new reserved words.
  3. Contextual/restricted identifiers: You may see terms like var, record, sealed, permits, or yield in examples. They are treated specially by the language and tooling, but they don’t change the classic table here. Your project’s compiler level determines availability/meaning.

Keyword groupings you will actually use

1) Types, declarations, and object model

2) Modifiers and access control

3) Control flow

4) Exceptions and contracts

5) Types and values

Modern usage patterns (quick demos)

Pattern matching with instanceof

Pattern variables let you combine the check and cast safely.


// Java 17+
Object value = getValue();
if (value instanceof String s) {
    System.out.println("Upper: " + s.toUpperCase());
}
  

Try-with-resources

Automatically closes resources that implement AutoCloseable.


try (var reader = java.nio.file.Files.newBufferedReader(path)) {
    System.out.println(reader.readLine());
} catch (java.io.IOException e) {
    // handle or rethrow
}
  

Concise decision logic with modern switch

Switch expressions (available in current JDKs) make selection logic simpler and less error-prone.


// Example shape area with modern switch (concise form)
double area = switch (shape.type()) {
    case CIRCLE   -> Math.PI * shape.radius() * shape.radius();
    case RECT     -> shape.width() * shape.height();
    case TRIANGLE -> shape.base() * shape.height() / 2.0;
};
  

What’s not obvious from the tables


Tables (Reference)

The following two tables enumerate the classic reserved keywords and related reserved words. Use the explanations above to map each keyword to its role in real code.

abstractassertbooleanbreak
bytecasecatchchar
classconstcontinuedefault
dodoubleelseenum
extendsfalsefinalfinally
floatforgotoif
implementsimportinstanceofint
interfacelongnativenew
nullpackageprivateprotected
publicreturnshortstatic
strictfpsuperswitchsynchronized
thisthrowthrowstransient
truetryvoidvolatile
while

Table 6.2 Java keywords and reserved words | Keywords required for Java SE 8

that cannot be used as names for Java variables

abstractdefaultgotopackagethis
assertdoifprivatethrow
booleandoubleimplementsprotectedthrows
breakelseimportpublictransient
byteenuminstanceofreturntrue
caseextendsintshorttry
catchfalseinterfacestaticvoid
charfinallongstrictfpvolatile
classfinallynativesuperwhile
constfloatnewswitch 
continuefornullsynchronized 

Useful quick checks