Java Naming Conventions Cheat Sheet

Java naming conventions are a set of rules and best practices that are followed while naming the variables, methods, classes, and other identifiers in Java code. These are some of the commonly accepted conventions in the Java community:

Identifier Type Convention Example
Class or Interface PascalCase, nouns, and should typically be descriptive. Student, CourseManager
Method camelCase, verbs, and often start with standard prefixes like get/set/is. getBalance, setHeight
Variable camelCase, descriptive, and should indicate the purpose of the variable. accountNumber, customerAddress
Constant UPPER_CASE with underscores separating words. MAX_WIDTH, DEFAULT_TIMEOUT
Package Lowercase and should use a hierarchical naming pattern. com.example.myapp
Generic Types Single uppercase letter, starting with ‘T’ for type. T, E for element, K for key, V for value
Enum PascalCase, and individual constants should be in UPPER_CASE. Color, DayOfWeek