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
| Item | Convention | Example |
|---|---|---|
| Classes | PascalCase | ArrayList, HttpServlet |
| Interfaces | PascalCase | Serializable, Comparable |
| Methods | camelCase | getUserById() |
| Variables | camelCase | firstName, itemCount |
| Constants | SCREAMING_SNAKE | MAX_VALUE, PI |
| Packages | all lowercase, dots | com.google.common |
| Enum values | SCREAMING_SNAKE | STATUS_ACTIVE |
| Generic types | Single uppercase | T, 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; }