Naming Conventions
Rules ¶
1. Names should not start or end with an underline or a dollar sign. [Mandatory] ¶
_name / __name / \$Object / name_ / name\$ / Object\$
2. Using Chinese, Pinyin, or Pinyin-English mixed spelling in naming is strictly prohibited. Accurate English spelling and grammar will make the code readable, understandable, and maintainable. [Mandatory] ¶
3. Class names should be nouns in UpperCamelCase except domain models: DO, BO, DTO, VO, etc. [Mandatory] ¶
MarcoPolo / UserDO / HtmlDTO / XmlService / TcpUdpDeal
marcoPolo / UserDo / HTMLDto / XMLService / TCPUDPDeal
4. Method names, parameter names, member variable names, and local variable names should be written in lowerCamelCase. [Mandatory] ¶
localValue / getHttpMessage() / inputUserId
5. Constant variable names should be written in upper characters separated by underscores. These names should be semantically complete and clear. [Mandatory] ¶
MAX_STOCK_COUNT
MAX_COUNT
6. Abstract class names must start with Abstract or Base. Exception class names must end with Exception. Test case names shall start with the class names to be tested and end with Test. [Mandatory] ¶
7. Brackets are a part of an Array type. The definition could be: String[] args; [Mandatory] ¶
String args[];
8. Do not add is as prefix while defining Boolean variable, since it may cause a serialization exception in some Java frameworks. [Mandatory] ¶
boolean isSuccess; The method name will be
isSuccess()and then RPC framework will deduce the variable name assuccess, resulting in a serialization error since it cannot find the correct attribute.
9. A package should be named in lowercase characters. There should be only one English word after each dot. Package names are always in singular format while class names can be in plural format if necessary. [Mandatory] ¶
![]()
com.webex.mct.utilcan be used as a package name for utils;MessageUtilscan be used as a class name.
10. Uncommon abbreviations should be avoided for the sake of legibility. [Mandatory] ¶
AbsClass (AbstractClass); condi (Condition)
Some abbreviations could be used such as MCT, MAV, UAS and GSS, etc.
11. There are two main rules for interface and corresponding implementation class naming: ¶
-
All
ServiceandDAOclasses must be interfaces based on SOA principle. Implementation class names should end withImpl. [Mandatory]CacheServiceImplto implementCacheService. -
If the interface name is to indicate the ability of the interface, then its name should be an adjective. [Recommended]
AbstractTranslatorto implementTranslatable.
12. The pattern name is recommended to be included in the class name if any design pattern is used. [Recommended] ¶
![]()
public class OrderFactory;public class LoginProxy;public class ResourceObserver;
Including corresponding pattern names helps readers understand ideas in design patterns quickly.
13. Do not add any modifier, including public, to methods in interface classes for coding simplicity. Please add valid Javadoc comments for methods. Do not define any variables in the interface except for the common constants of the application. [Recommended] ¶
method definition in the interface:
void f();
constant definition:String COMPANY = "cisco";
In JDK8 it is allowed to define a default implementation for interface methods, which is valuable for all implemented classes.
14. An Enumeration class name should end with Enum. Its members should be spelled out in upper case words, separated by underlines. [Recommended] ¶
Enumeration is indeed a special constant class and all constructor methods are private by default.
![]()
Enumeration name: DealStatusEnum; Member name:SUCCESS / UNKOWN_REASON.
15. Naming conventions for different package layers: ¶
1. Naming conventions for Service/DAO layer methods [Recommended] ¶
- Use get as name prefix for a method to get a single object. - Use list as name prefix for a method to get multiple objects. - Use count as name prefix for a statistical method. - Use insert or save as name prefix for a method to save data. - Use delete or remove as name prefix for a method to remove data. - Use update as name prefix for a method to update data.
2. Naming conventions for Domain models [Recommended] ¶
- Data Object: *DO, where * is the table name. - Data Transfer Object: *DTO, where * is a domain-related name. - Value Object: *VO, where * is a website name in most cases. - POJO generally point to DO/DTO/BO/VO but cannot be used in naming as *POJO.