What are java identifiers

Every name in java is called identifier such as,

  • Class-name
  • Method-name
  • Variable-name

Rules to declare identifier:

  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

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

class Test

{

int NUMBER=10;

 int number=10;

int Number=10;

}

3.The identifier should not duplicated & below example is invalid because it contains duplicate variable name.

class Test{

int a=4;

int a=5;

}

4.In the java applications it is possible to declare all the predefined class names & interfaces names as a identifier but it is not recommended to use.
class Test
{
public static void main(String[] args)
{
int String=10;

float Exception=10.2f;
System.out.println(String);
System.out.println(Exception);

}

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

class Test
{
int if=10;
int try=20;
}

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

 

}

Published by Atul maurya

i am student of computer science & engineering .i want to become a java developer. my hobby is to learn programming language in easy way.

Leave a comment

Design a site like this with WordPress.com
Get started