Reserved Words in Java

Format
mla apa chicago
Your Citation
Leahy, Paul. "Reserved Words in Java." ThoughtCo, Aug. 27, 2017, thoughtco.com/reserved-words-in-java-2034200. Leahy, Paul. (2017, August 27). Reserved Words in Java. Retrieved from https://www.thoughtco.com/reserved-words-in-java-2034200 Leahy, Paul. "Reserved Words in Java." ThoughtCo. https://www.thoughtco.com/reserved-words-in-java-2034200 (accessed September 26, 2017).
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:

 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.