Friday, December 30, 2016

Use predefined class as identifiers in JAVA

E. In java application, we are able to use all predefined class names & interface names as identifiers.

EX: 1
int Exception= 10;
System.out.println(Exception);

Status: No compilation error
Output: 10

Note: Here Exception is an int variable.
---------------

EX: 2
String String = "String";
System.out.println(String);

Status: No compilation Error.
Output: String

Note: Here First String is as String class, 2nd String as a variable, 3rd String as value of variable.
--------------

EX: 3
int System = 10;
System.out.println(System);

Status: Compilation Error.
Reason: In java application , if we declare "System" as an integer variable then in the remaining program, we must use that System as integer variable only, we must not use that System as original class name, if we use "System" as original class name then compiler will rise an error.

In the above context if wi want to use System as class name, then we have to use its "fully qualified name" providing class name along their package name is called as "Fully qualified name".

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);
}
}

Status: No compilation error
Output:
10
20
---------------------------

Along with the above rules & regulations, JAVA has provided the following suggestiong to use identifiers in JAVA application:

1. It is suggestible to provide identifier with a particular meaning.
EX:
String aa = "abc123"; ---------> Not Suggestible
String accNo = "abc123"; ------> Suggestible

2. In Java Application, there is no length restriction for the identifiers, but, it is suggestible to manage length of the identifier around 10 symbols.
EX: 
String temporaryemployeeaddress = "Hyd"; -------> Not Suggestible
String tempEmpAddr = "Hyd"; --------------------> Suggestible

3. If we have multiple words with in a single identifier then it is suggestible to separate multiple words with special notation like '-' symbol.
EX:
String tempEmpAddr = "Hyd"; -----> Not Suggestible
String temp_Emp_Addr = "Hyd"; ---> Suggestible

You May Also Like --> Classes Vs Interference 

No comments:

Post a Comment