Java Identifiers 
In java , Name of variables , methods , classes , packages , interfaces are known as the identifiers. java identifiers are used for identification purpose.
Identifiers must be composed of letters, numbers, the underscore (_) and the dollar sign ($). Identifiers may only starts with a letter, the underscore(_) or a dollar sign($).


public class Employee  

public static void main(String args[])

int a=20;

Identifiers in above java code

Employee : Class name 
main : Method name 
String : Predefined class name 
args : Variable name 
a : Variable name

Rules to declare Java Identifiers 
There are some predefined rules to declare identifiers which user have to followed otherwise compile throw compile-time-error.

In java,Identifiers in java should contains alphanumeric character (uppercase[A-Z] and lowercase [a-z]) , Numbers [0-9] ,dollar [$] , Underscore [-]
int xyz=200;  Valid
int _ab=500;  Valid
int $ab=800;  Valid
int a-bd=900; Invalid
int a jk=980;  Invalid


Identifiers in java should not starts with number [0-9].
int 2ab=100;  Invalid

Identifier in java are cases sensitive just because java programming language is a cases sensitive language .
int a=10;
int A=10;
Here java consider both A and a as different variables .

In java identifiers can not be duplicate ,it must be unique .

Length limit not define for declaring the identifiers .

In java it is not possible to use java keywords as identifiers.
int if=20;     Invalid
int while=30;Invalid

Valid identifiers in java
The list of legal identifiers in java given below 

  • MyVariable
  • myvariable
  • x
  • i
  • _myvariable
  • $myvariable
  • _9id
  • ABc
  • This_is_Method
  • abc123
  • sv23

Invalid Identifiers in java

List of illegal identifiers in java given below 

  • My Variable // Contains space
  • 9tv // Starts with a digit
  • a+d //  Contains + sign 
  • test1-2-3 // Contains hyphen 
  • A's // Contain Apostrophe 
  • A_&_b // Contains ampersand

Hope !!! The above lesson java identifiers helpful for you...

Technology Team, 

UP Consultancy Services 

Tags : java identifiers , identifiers in java , declaration of identifiers , rules for defining identifiers , legal identifiers in java , illegal java identifiers ,rule for identifiers 

Java Naming Convention with Example