Master Java Naming Conventions: Boost Code Readability and Quality
This article shares practical Java naming guidelines—avoiding meaningless letters, using proper English, handling singular/plural forms, boolean properties, method names, CRUD operations, and abbreviations—to help developers write clearer, higher‑quality code through disciplined naming practices.
Many developers find reading high‑quality open‑source projects like Spring or Apache Commons a pleasure because of their excellent code quality and precise naming.
Writing high‑quality code requires long‑term practice, but good naming can be achieved with solid English grammar and self‑awareness.
Avoid Meaningless English Letters
Do not use arbitrary single‑letter names; replace them with meaningful terms such as index.
Avoid Pinyin
Using Chinese pinyin in identifiers makes code hard to understand for others.
Use Accurate English
Use singular nouns for single objects (e.g., Account, Customer).
Use plural nouns for collections (e.g., ListAccounts, SetStrategies).
For boolean properties, avoid the is prefix that can produce awkward getter/setter names; instead use an adjective like closed so the methods become getClosed / setClosed.
Method Naming
Prefer clear, descriptive names; avoid mixing nouns and verbs or using unclear abbreviations.
CRUD Method Naming
Create/Add: Use create for creation and add for addition, distinguishing their semantics.
Update: Prefer modify over alter or update.
Read: Use get or load for single objects, list for collections, and search for conditional queries.
Delete: Use delete rather than remove to convey removal.
Avoid Unclear Abbreviations
Do not use cryptic short forms that obscure intent.
Do Not Use Technology‑Specific Prefixes/Suffixes
Instead of forcing interfaces to start with “I” or DTO/DAO suffixes, name classes based on business concepts, e.g., CustomerInfo or AccountRepository, to keep the focus on domain logic.
Member Variables Should Not Duplicate Class Names
Within a class like Account, avoid redundant fields such as accountId; simply use id for clarity.
These naming rules, though simple, can significantly improve code readability and maintainability.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
