elibraryportal Logo

Java Naming Conventions

Java naming convention is a components require names. Names used for classes, variables and methods are called identifiers.

Some other rules that followed by identifiers.

Class

  • It should start with the uppercase letter.
  • Example: -

Interface

  • It should start with the uppercase letter.
  • It should be an adjective such as Runnable, Remote, ActionListener.
  • Use appropriate words, instead of acronyms.
  • Example: -

Method

  • It should start with lowercase letter.
  • It should be a verb such as main(), print(), println().
  • If the name contains multiple words, start it with a lowercase letter followed by an uppercase letter such as actionPerformed().
  • Example:-

Variable

  • It should start with a lowercase letter such as id, name.
  • It should not start with the special characters like & (ampersand), $ (dollar), _ (underscore).
  • If the name contains multiple words, start it with the lowercase letter followed by an uppercase letter such as firstName, lastName.
  • Avoid using one-character variables such as x, y, z.
  • Example :-

Package

  • It should be a lowercase letter such as java, lang.
  • If the name contains multiple words, it should be separated by dots (.) such as java.util, java.lang.
  • Example :-

Constant

  • It should be in uppercase letters such as RED, YELLOW.
  • If the name contains multiple words, it should be separated by an underscore(_) such as MAX_PRIORITY.
  • It may contain digits but not as the first letter.
  • Example :-