Monday, 8 August 2016

Identifiers :


1.       Identifiers :
Identifiers is a name assigned to the programming elements like variables, method, class, abstract classes
Ex:-
>>int a=10;
>>intàdata type
>>aà variable 
>>=à Operator
>>10àConstant
>>;àSpecial Symbol
To use identifiers in java programs, java has provided following rules and regulations.
1.       Identifiers must not be started with a numbers, identifiers may start with an alphabet, _symbols,  $ symbol, but the subsequent symbols may be a number, an alphabet, _ symbol, $ Symbol.
Ex:-
>>int 9eno=111;àInvalid
>>String ename= “sai”;àValid
>>float emp9Sal= 900000.0f;àValid
>>String _empAddr= “Hyd”;àValid
>>float $esal=50000.0f;àValid
>>String emp_Qual= “B.tech”àValid
2.       Identifiers are not allowing all special symbols, except _Symbol and  $ symbol. All Operators.
ex:-
>>String emp-Name= “Sai”;àInvalid
>>String emp_Addr= “Hyd”;àValid
>>String emp@Hyd= “Sai”;àInvalid
>>String #empAddr= “Hyd”;àInvalid
>>int emp.No=111;àInvalid
>>float emp+Sal=50000.0f;àInvalid
3.       Identifiers are not allowing space in the middle,
Ex:-
>>for Name(“A”);àInvalid
>>forName(“A”);àValid
>>get Input Stream();àInvalid
>>getInputStream();àvalid
4.       Identifiers must not be duplicated within the same scope, identifiers may be duplicated in two different scopes.
Ex:-
class A
{
                int i=10;
                long i=20;//Error
                byte j=40;
                void m1()
                {
                                float j=20.0f;
                                double i=22.22;
                                short j=30;// Error
                }
}

5.       In java application s we can utilize all predefined class names and interface names as identifiers
Ex:-

int Exception=10;
System.out.println(Exception);

Status: No Compilation Error
Output : 10

Date :29- july-2016

Ex:-
class A
{
                public static void main(String[] args)
                {
                                String String= "String";
                                System.out.println(String);
                }
}
Status: No Compilation Error
Output :  String

Ex:-
class A
{
                public static void main(String[] args)
                {
                                int System =10;
                                System.out.println(System);
                }
}

 Status: Compilation Error
Reasons :- In java application, if we declare “System” as an integer variable then, we must use System  Integer Variable only in the remaining part of the programming, we must not use Sytem as original class name, if we use System as original class in the remaining programming then compiler will rise an error.
In the above context, if we want to use System has class Name then, we have to use fully qualified name of the classes.
Note:- 
Specified class name and interface name along with their package name is called “Fully Qualified Name”.
Ex:-
java.util.ArrayList
java.io.BufferedReader____etc

Ex:-
class Test
{
                public static void main(String[] args)
                {
                                int System=10;
                                java.lang.System.out.println(System);
                                System=System+10;
                                java.lang.System.out.println(System);
                                System=System+10;
                                java.lang.System.out.println(System);
                }
}

Status : No compilation Error
Output : 10
                20
                30
Along with the above relations and regulations
Java has provided the following suggestion to use identifiers.
1.       In  java applications, it is suggestible to provide identifiers with a particular meaning
Ex:-
String xxx= “abc123;àNot Suggestible
String accNo= “abc123”àSuggestible
2.       No length restriction for the identifiers in java applications ,but, it is suggestible to provide length of the identifiers around 10  Symbols.
Ex:-
String temporaryemployeeaddress= “ Hyd”;àNot suggestible
String tempEmpAddr= “Hyd”;àSuggestible
3.       If we have multiple words within a single identifiers then it is suggestible to separate multiple word with the special notations like “_” systems.
Ex:-
String tempEmpAddr= “Hyd”;àNot Suggestible

String  temp_Emp_Addr= “Hyd”àSuggestible 

No comments:

Post a Comment