Variable naming conventions in Java?

Solution 1:

You can find the naming in the Java Code Conventions.

A quick summary:

  • For classes, use UpperCamelCase.
  • For class members and local variables use lowerCamelCase
  • For packages, use reverse URI, e.g. org.acme.project.subsystem
  • For constants, use ALL_CAPS.

Solution 2:

Generally, all variables will start with lower case:

int count = 32;
double conversionFactor = 1.5d;

Some people like to put static constants in all case:

public static final double KILOGRAM_TO_POUND = 2.20462262;

Things get more annoying when you deal with acronyms, and there is no real standard on whether you should use:

HTMLHandler myHtmlHandler; 

or

HTMLHandler myHTMLHandler.

Now, either way, note that the class names (Object, String, HTMLHandler) always start with a capital letter, but individual object variables start lowercase.