JAVA KEYWORDS & IDENTIFIERS

Java keywords are reserved words that are predefined, while java identifiers are used for identification purposes. Learn more about Java Keywords and Identifiers in this module. Before diving into keywords and identifiers tutorials, you should know Data Types in Java.

Table of Contents

[hide]
  • What is a Java Keyword
  • what is a Java Identifier
  • Java Identifier Naming Rules

What is a Java Keyword

Java Keywords are the set of predefined words that are provided by Java Programming Langauge . They are also called "reserved words" which are case-sensitive.

These reserved words cannot be used as a variable name, class name or an method name. In Java there are 50 such keywords given in the below table.

List of Keywords in Java

abstractassertbooleanbreakbyte
casecatchcharclassconst
continuedefaultdodoubleelse
enumextendsfinalfinallyfloat
forgotoifimplementsimport
instanceofintinterfacelongnative
newpackageprivateprotectedpublic
returnshortstaticstrictfpsuper
switchsynchronizedthisthrowthrows
transienttryvoidvolatilewhile

In the above table keyword goto and const are never used though they are reserved. You can't use true , false and null as identifiers besides these keywords as well. The explanation is, they are literals

Example

int age = 32; // "age" is an identifier here, while "int" is a reserved word.

What is a Java Identifier

java Identifier is any name, it can be a variable name, method name, class name or interface name. In the above example variable name age is also know as identifier. If you want to learn more about variables then refer to Java variables.

Example

// Java program to illustrate identifiers in Java
public class IdentifyExample{
      public static void main(String args[]){  
         int value = 10; 
    }
}

In the above example there are five identifiers namely :

1. IdentifyExample : It is a class name.
2. main : It is a main method.
3. String : It is a predefined class name.
4. args : args are the string variables.
5. value : value is the name of variables.

Java Identifier Naming Rules

There are some rules which we have to follow before defining Java Identifier. If these rules are not followed then we get compile time error. Rules for defining Java identifiers are :-

  • 1. An identifier name should begin with letter of a alphabet , a ($) dollar sign, or an underscore. It is encouraged to always use a letter of a alphabet rather than using dollar sign and underscore.
  • 2. identifier can contain any combination of letters and digits(0-9) only after the first initial letter. Spaces and Special characters are not allowed like &(ampersand).
  • 3. Usage of one-character variable is not recommended. Ex e, f, g.
  • 4. Java Identifiers are case-sensitive.
  • 5. You cannot use java keywords also known as reserved words for a identifier name.