Skip to main content

Identifier In Java

Identifier In Java :

 -used for identification purpose.

-name in java program is called identifier.

- It can be class name, Method name ,variable name.

Example :

class CollegeManagement{

            public static void main(String[] args){

                String collegeName="RECOEM";

            }

}


In above program , identifiers are :

1.name of the class -> CollegeManagement

2.name of method -> main

3.name of class -> String

4.name of array -> args

5.name of variable -> collegeName



Rules for defining Identifier :


-allowed characters in Java Idenfier :

a to z

A to Z

0 to 9

$
_

 

NOTE

-identifier will never start with number.

-reserved words we cant use as identifiers, but we can used as predefined class name or interface name as Identifier ,but it is not good practice.

-Java identifiers are case - sensitive , java is a case sensitive programming language.

Example :

String studentName="Swapnil V";

String STUDENTNAME="Neel";

here studentName and STUDENTNAME are two different identifiers.


Example of Identifiers valid and invalid :

total_marks : valid


123total_marks : invalid

college$Department : valid

studentName# : invalid

Integer : valid

int : invalid here int is Reserved Word we cant use as Identifier

Int valid

marks12 : valid

name@Bank : invalid

department2Name : valid