Java Naming Conventions

The rules and conventions for naming a variable are

1. Variable names are case sensitive. A variable name can be any legal identifier of an unlimited-length sequence of Unicode letters and digits, beginning with the dollar sign “$”, a letter, or the underscore character “_”.As per the convention, however, is to always begin the variable name with a letter, not “$” or “_”. White space is not allowed in the variable name.

2. Subsequent characters may be letters, digits, and dollar signs or underscore characters.

3. If the name of a variable consists of only one word, spell that word in all lowercase letters. If it consists of more than one word, then the variable name will be written in camel case (capitalize the first letter of each new word without spaces).

4. The names getRadius() and getArea() are prime examples of this convention.

5. If we are declaring a variable that stores a constant value, such as static final int PI = 3.14, the convention changes slightly, all the characters using in variable names will be in upper case and subsequent words with the underscore character. By the convention, the underscore character is never used elsewhere.

We can declare packages names using any standard Java naming rules. By the convention, however, packages begin with lower case letters. In this way, it is very easy for users to distinguish package names from class names when looking at an explicit reference to a class. We know that all class names, again by the convention, begin with an only uppercase letter.

Java Naming Conventions