Variable naming conventions in Java?

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.


You can find the naming in the Java Code Conventions.

A quick summary:

  • For classes, use upper camel case.
  • For class members and local variables use lower camel case
  • For packages, use reverse URIs, e.g., org.acme.project.subsystem
  • For constants, use uppercase.