Identifiers in Java

Table of Contents

Identifiers in Java

So, What is an Identifier and how does it look like?

Identifiers are used by the programmers to name the variables, interface, method, class, object, packages, etc.

Basically it helps out the programmer to choose what to name what so that it can be easier for the programmers to identify their own creations. 

A valid identifier in Java must be of the following pattern and follow some basic rules –

  • It must begin with a letter (A to Z or a to z), currency character ($) or an underscore (_).
  • It can have any combination of characters after the first character.
  • It cannot be a keyword.
public class Sample {
   public static void main(String args[]) {
      int abc = 1;
      int _abc = 2;
      int $abc = 3;
      int abc123 = 4;
      int ABC = 5;     
      System.out.println("value if the variable num: "+abc);
      System.out.println("value if the variable _num: "+_abc);
      System.out.println("value if the variable $num: "+$abc);
      System.out.println("value if the variable num123: "+abc123);
      System.out.println("value if the variable NUM: "+ABC);
   }
}

Above used variables are the various valid ways of using Identifiers.

Previous Tokens in Java
Next Constants and Variables in Java

Leave a Reply