Java

  1. Home
  2. Computing & Technology
  3. Java

Reserved Words in Java

By Paul Leahy, About.com

There are some words that you cannot use as object or variable names in a Java program. These words are known as “reserved” words; they are keywords that are already used by the syntax of the Java programming language.

For example, if you try and 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..

   }
}
It will not compile, instead you will get the following error:
<identifier> expected

The table below lists all the words that are reserved:

abstract assert boolean break byte case
catch char class const* continue default
double do else enum extends false
final finally float for goto* if
implements import instanceof int interface long
native new null package private protected
public return short static strictfp super
switch synchronized this throw throws transient
true try void volatile while

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

Explore Java

About.com Special Features

Java

  1. Home
  2. Computing & Technology
  3. Java
  4. Java Syntax
  5. Reserved Words in Java

©2009 About.com, a part of The New York Times Company.

All rights reserved.