Recent Posts

Responsive Ads Here

Wednesday 6 April 2016

Identifiers in Java ,General examples for identifiers in java

what is identifier



 Technical Description:- A name in a java program is called identifier. It can be class name or variable name or method name or label name. We can not  set or retrieve value without knowing identifiers.

Example :
                                  identifiers in programming


General Description:- suppose if you want to make a call to some one of your friend. So how can you make a call to them? either mobile or network ,for that we need identification of his/her number or social id.Then only we can able to talk with them ,so identity is very important and it always unique ,or else we will get ambiguity(Duplication).   

                          

Example : 

8123456789  : This is Number identity,by this identity we can make a call to them.

Nagendra : This is nagendra (of course in real time different people having same name ,but do not apply this scenario to Java identifier ,because in java we can protect our identifier (name) using private keyword )

Code : This is Number identity,country code ,each country having unique number (IND +91,USA +1 ,..etc)

India : This is name identity  
We can take so many general scenario as examples like Vehicles registration Numbers,Passport Numbers,Bank Account Numbers etc .


Rules to define Identifiers :
1. The only allowed characters in java identifiers are
A to Z
a to z
0 to 9
_(Under score)
$

Note:  If we are trying to use other character we will get compile time error

Example :

All_Number -->variable name is correct
all_number -->variable name is correct
#all   -->variable name is incorrect (because java does  not allow special characters as in variable name)
_$Z  -->variable name is correct

2. Identifier should not start with digit

 Example :

123Total variable name is incorrect
Total123 variable name is correct

3.Java Identifiers are case sensitive, which means Number is different with NUMBER

Class Test
{
int NUMBER=10;
int nUmber=20;
int NumBer=30;
System.out.println(“All are different ”);
}
  
In java we can differentiate identifiers with respect to case.CAT is different from cat,

4.There is no length limit for java identifier.But it is not recommended to take more than 15 length

5. Keywords cannot be used as identifiers
      
     Example :Do not use  int (its one of the keyword in java )as variable name

   6.All predefined java class names and interface names we can use as  identifiers.Even though its legal,but it is not recommended.We can use ,but not recommended

    Class Test
    {
    int String=10;
    System.out.println(String);
    }

   Output: 10

   Class Test
   {
   int Runnable=20;
   System.out.println(Runnable);
   }

  Output : 20


No comments:

Post a Comment