Identifier and Reserved Words


A name in java program is called identifier which can be used for identification purpose. It can be class name or method name or variable name or label name.

public class Test {
   public static void main(String[] args) {
     int a = 10;
     System.out.println("Hai This is Ashok");

Above example contains 5 identifiers. They are Test, main, String, args and a.

  • The only allowed characters in java identifiers are a to z, A to Z, 0 to 9, $ and _ (Underscore). If we are using any other character then we will get compilation error.
  • Identifiers can’t start with digit i.e., 123name is not valid.
  • Java identifiers are case sensitive of course java language itself considered as case sensitive programming language. i.e., name, Name, NAME both are different variable names.
  • There is no length limit for java identifiers but it is not recommended to take too length identifiers.
  • We can’t use reserved words as identifiers otherwise we will get compilation error. i.e., int if = 20; here we will get compilation error.
  • All predefined java class names and interface names we can use as identifiers. i.e., int String = 20; here we won’t get any compilation error. But it is not a good programming practice.
Reserved Words

In java some words are reserved to represent some meaning or some functionality. Such type of words are called as Reserved Words. There are 53 reserved words in java. 50 are keywords and 3 are literals (true, false, null). The 50 keywords are classified in to following.

1. Reserved words for data types (8)

byte, short, int, long, float, double, boolean, char

2. Reserved words for flow control (11)

if, else, switch, case, default, while, do, for, break, continue, return

3. Reserved words for modifiers (11)

public, private, protected, final, abstract, static, synchronized, native, strictfp, transient, volatile

4. Reserved words for Exception handling (6)

try, catch, finally, throw, throws, assert (Used for debugging purpose)

5. Reserved words for class related (6)

class, interface, package, import, extends, implements

6. Reserved words for object related (4)

new, instanceof, super, this

7. Reserved words for return type (1)



In java return type is mandatory if a method won’t return anything. Such type of methods we should declared with void return type. But in C language return type is optional and default return type is int.

8. Unused keywords (2)

goto, const

Usage of goto keyword created several problems in old languages like C and C++. Hence SUN people band this keyword in java where as we use final keyword instead of const.


goto and const are unused keywords if we are trying to use then we will get compilation error.

9. enum keyword (1) (From java 1.5V)

we can use enum to define a group of named constants.


enum Month {


  1. All 53 reserved words in java contain only lower case alphabets
  2. In java we have only new keyword but not delete keyword because destruction of useless objects is the responsibility of Garbage Collector.
Identifier and Reserved Words

Scroll to top