Java identifiers

.

Java identifiers
In java every name is called identifier such as,Class-name,Method-name,Variable-name…etc


Identifier Example
The example of identifier are listed below

public class Testing
{

public static void main(String[] args)
{

int a=10;

}

}

In Above Example there are 5 Identifier are used which listed below

Test     ->  Represent Class name
main   ->  Represent method name
String ->  Represent predefined class name
args   ->   Represent variable name
a        ->   Represent variable name

Rules and Regulation  to declare identifier in java
Follow the below steps to declare the identifier in java


Rule-1 
An identifier contains group of Uppercase & lower case characters, numbers, underscore& dollar
sign characters but not start with number.

int abc=10; --->valid
int _abc=30;--->valid
 int $abc=40;--->valid
int a-bc=50;--->not valid
 int 2abc=20; ---> Invalid
 int not/ok=100 --->invalid

Rule-2. 
Java identifiers are case sensitive of course java is case sensitive programming language. The
below three declarations are different & valid.

class Qa
int a=10;
Int A=20;
}

Rule-3. 
The identifier must be unique.(duplicates are not allowed)

Class A{}
Class A{}

Rule-4. 
It is possible to use predefined class names & interfaces names as a identifier but it is not
recommended.

class Qa
{
public static void main(String[] args)
{
 int String=10;
intSerializable=20;
System.out.println(String);
System.out.println(Serializable);
}
}

Rule-5
 It is not possible to use keywords as a identifiers.

int if=10;
 int try=20; //Invalid

Rule-6.
 There is no length limit for identifiers but is never recommended to take lengthy names because
it reduces readability of the code.




Post a Comment

0 Comments