Identifiers and its Naming Conventions in NetBeans: Java

In Java Programming, Identifiers are fundamental building blocks of a program and are used as the general terminology for the names given to different parts of the program viz. variables, objects, classes, function, arrays etc.

Identifier forming rules of Java state the following:

  • Identifiers can have alphabets, digits and underscores and dollar sign characters.
  • They must not be a keyword or Boolean literal or null literal.
  • They must not begin with a digit.
  • They can be any of length.
  • Java is case sensitive i.e., upper-case letters and lower-case letters are treated differently.    

The following are some valid identifiers:

Myfile                 DATE9_7_77        ZT0Z9          A_to_Z
MYFILE                _DS                  _HJI3_JK     isLetterorDIgit
_CHK                   FILE13                 αρετη         $1_to_$10

The following are some invalid identifiers:

DATA_REC             contains special character _ (other than A - Z, a – z and _or )$
29CLCT                   starting with digit
break                      reserved keyword
My.file                   contain special character.

Identifier Naming Conventions:

While making identifier names, certain convention are followed. These are:

  • The names of public methods and instance variables should begin with a lower case letter e.g. Maximum sum
  • For names having multiple words, second and subsequent words beginning character is made capital so as to enhance readability e.g. avgSalaryofEmployees, dateofBirth
  • Private and local variable should use lower case letter e.g. Width, result, final_score
  • The class names and interface names begin with an upper case letter e.g. InitialClass, Employee, and Student
  • The constant should be named using all capital letters and underscores e.g. MAX_VALUE, MAX_MARKS, SPECIAL_SALARY, and TOTAL


Post a Comment