Java Naming Conventions: Oracle's Official Code Conventions

5 min read

Java has well-established naming conventions from Oracle (originally Sun Microsystems) that every Java developer follows.

Convention Table

ItemConventionExample
ClassesPascalCaseArrayList, HttpServlet
InterfacesPascalCaseSerializable, Comparable
MethodscamelCasegetUserById()
VariablescamelCasefirstName, itemCount
ConstantsSCREAMING_SNAKEMAX_VALUE, PI
Packagesall lowercase, dotscom.google.common
Enum valuesSCREAMING_SNAKESTATUS_ACTIVE
Generic typesSingle uppercaseT, E, K, V

Getter/Setter Pattern

// Property: firstName
public String getFirstName() { return firstName; }
public void setFirstName(String firstName) { this.firstName = firstName; }
// Boolean: active
public boolean isActive() { return active; }

Convert

camelCase, PascalCase, CONSTANT_CASE. Hub.