Identifiers are fundamental building blocks of a program and are used as the general terminology for the names given to different parts of program. viz variables, functions, arrays, classes, etc.
Identifier naming rules:
- They can have alphabets, digits and underscore(_) & Doller($) sign characters.
- They must not be a keyword or Boolean literal or null literal.
- They must not begin with a digit.
- They can be of any length.
- Keywords can not be used as identifiers.
- Java is case sensitive i.e. upper-case & lower-case letters are treated differently.
Some valid identifiers:
Myname, Date_2_4, isLetter, $12_to_56.
Some invalid identifiers:
My-name, 25abc, for.
Identifier Naming Conventions:
- The name of public methods and instance variables should begin with a lower case letters.
- Example: maximum sum
- For names having multiple words, second and subsequent words beginning character is made capital so as to enhance readability.
- Example: avgSalaryOfEmployees, dateOfBirth
- Private & local variables should use lower case letters.
- Example: width, result, final_score
- The class names & interface names begin with an uppercase letter.
- Example: InitialClass, Employee, Student
- The constant should be named using all capital letters and underscores.
- Example: MAX_VALUE, MAX_MARKS, TOTAL