Reserved Words in Java

Businesswoman sitting at desk working on computer
Thomas Barwick/Stone/Getty Images

Some words cannot be used as object or variable names in a Java program. These words are known as reserved words -- keywords that are already used by the syntax of the Java programming language.

For example, if you try to create a new class and name it using a reserved word:

 // you can't use finally as it's a reserved word!
 class finally {
 
    public static void main(String[] args) {
 
       //class code..
 
    }
 }

The program will not compile; instead, you will get the following error:

<identifier> expected 

List of Reserved Java Keywords

The following keywords are reserved:

abstractassertbooleanbreakbytecase
catchcharclassconstcontinuedefault
doubledoelseenumextendsfalse
finalfinallyfloatforgotoif
implementsimportinstanceofintinterfacelong
nativenewnullpackageprivateprotected
publicreturnshortstaticstrictfpsuper
switchsynchronizedthisthrowthrowstransient
truetryvoidvolatilewhile 

 

Even though goto and const are no longer used in the Java programming language, they still cannot be used as keywords.