Return to site

🔸 REMINDER: JAVA NAMING CONVENTIONS 🧭

October 4, 2025

Want cleaner APIs and fewer “what-does-this-mean?” moments? Here’s a quick refresher you can share with the team. ✨

PACKAGES 📦

▪️ lowercase, dot-separated: com.example.billing

▪️ No underscores/camel case; use domain reversed; keep it stable over time.

CLASSES & INTERFACES 🧱

▪️ UpperCamelCase nouns (interfaces can be nouns or adjective-like): InvoiceService, PaymentGateway, Runnable

▪️ One concept per type; avoid abbreviations: prefer Configuration over Cfg.

METHODS 🛠️

▪️ lowerCamelCase, verbs/action phrases: processOrder(), toJson()

▪️ Side-effect vs query clarity: save() vs findById().

FIELDS (INSTANCE/STATIC, NON-CONSTANT) 📄

▪️ lowerCamelCase nouns: retryCount, userRepository

▪️ Keep scope tight; avoid Hungarian notation or type prefixes.

CONSTANT FIELDS 🔒

▪️ UPPER_SNAKE_CASE, public static final: DEFAULT_TIMEOUT_MS,

MAX_RETRIES

▪️ Constants belong to the most relevant type; don’t scatter global constants.

LOCAL VARIABLES 🧪

▪️ lowerCamelCase, short yet meaningful: sum, startTime, line

▪️ Keep context close: small names for tiny scopes (i, n in tight loops).

TYPE PARAMETERS (GENERICS) 🧩

▪️ Single uppercase letters for common roles: T (type), E (element), K/V (key/value), R (result)

▪️ Use descriptive multi-letter only when clarity demands: is acceptable if it truly helps.

COMMON PITFALLS 🚩

▪️ Don’t mix styles: never User_Service or DoStuff()

▪️ Avoid acronyms yelling: use HttpClient, not HTTPClient (capitalize first letter only: Http, Xml)

▪️ Names reflect intent, not implementation: cache > hashMap for a Map field.

TLDR 🧾

▪️ Packages: com.company.project (all lowercase)

▪️ Types: UpperCamelCase

▪️ Methods/fields/local vars: lowerCamelCase

▪️ Constants: UPPER_SNAKE_CASE + public static final

▪️ Generics: T,E,K,V,R (use clear names when needed)

TAKEAWAYS ✅

▪️ Consistent naming = faster onboarding & fewer bugs.

▪️ Choose intent-revealing names; keep acronyms readable.

▪️ Follow scope: the smaller the scope, the shorter the name.

▪️ Be boring—conventions beat creativity for names.

#Java #CleanCode #JavaTips #NamingConventions #SoftwareEngineering #CodeQuality #OOP #BestPractices #DevTips #Readability