Alibaba Java Development Manual
Java Development Manual
Version number
Develop a team
Update Date
Notes
1.0.0
Alibaba Group Technology Department
2016.12.7
Exposing to the Java industry for the first time
I. Programming protocol
(i) Naming conventions
1. "Mandatory" all programming-related names cannot begin with an underscore or dollar sign, or end with an underscore or dollar sign.
Anti-Example: _name/__name/$Object/name_/name$/object$
2. "Mandatory" all programming-related naming is strictly prohibited the use of Pinyin and English mixed mode, but also do not allow direct use of the Chinese way.
Description: Correct English spelling and grammar can make reading readers easy to understand and avoid ambiguity. Note that even if the pure phonetic naming method
should also avoid adoption.
Anti-Example: dazhepromotion [discount]/Getpingfenbyname () [rating]/int variable = 3;
Positive example: Ali/alibaba/taobao/cainiao/aliyun/youku/hangzhou and other international general
Name can be considered in English.
3. The "Mandatory" class name uses the Uppercamelcase style and must be in the Hump form, except in the following cases: (Domain model
Related name) Do/dto/vo/dao and so on.
Positive example: marcopolo/userdo/xmlservice/tcpudpdeal/tapromotion
Anti-Example: macropolo/userdo/xmlservice/tcpudpdeal/tapromotion
4. "Mandatory" method name, parameter name, member variable, local variable all uniform use Lowercamelcase style, must comply with
Hump form.
Positive example: Localvalue/gethttpmessage ()/Inputuserid
5. "Mandatory" constant name all uppercase, the words are separated by an underscore, to achieve the semantic expression of complete and clear, not too long name.
Positive example: Max_stock_count
Anti-Example: Max_count
6. "Force" abstract class naming begins with abstract or base; Exception class naming uses exception end; test class life
The name begins with the name of the class that it is testing, ending with test.
1 km /
Alibaba Java Development Manual
7. The "force" bracket is part of the array type, and the array is defined as follows: string[] args;
Anti-Example: do not use string args[as a way to define
8. "Force" Pojo any boolean-type variable in the class, do not add is, or partial framework parsing can cause serialization errors
Miss.
Anti-Example: a property defined as a Boolean issuccess of the base data type, and its method is issuccess (), RPC
When the framework is in reverse parsing, the attribute name "thought" corresponds to the success, causing the property to be fetched and then throwing
Abnormal.
9. "Mandatory" package name unified use lowercase, dot delimiter between there is and only a natural semantics of English words. Package Name Unified Use
Singular form, but if the class name has a plural meaning, the class name can be in the plural form.
Example: The utility class package name is Com.alibaba.mpp.util and the class name is messageutils (this rule references spring
Frame structure)
10. "Mandatory" to eliminate the complete irregular abbreviations, to avoid the hope that the text does not know righteousness.
Anti-Example:< a business code >abstractclass "abbreviation" named absclass;condition "abbreviation"
Condi, this kind of arbitrary abbreviation severely reduces the readability of the code.
11. "Recommended" If the design pattern is used, it is recommended to reflect the specific pattern in the class name.
Description: The design pattern is embodied in the name, which helps the reader to understand the architecture design idea quickly.
Positive example: public class orderfactory;
public class Loginproxy;
public class Resourceobserver;
12. Methods and properties in the "recommended" interface class do not add any modifiers (public or not) to keep the code simple
and add a valid Javadoc annotation. Try not to define variables in the interface, and if you have to define variables, you must be
is associated with an interface method and is the underlying constant for the entire application.
Positive example: interface method signature: void F ();
Interface base constants represent: String company = "Alibaba";
Anti-Example: interface method definition: Public abstract void f ();
Note: The JDK8 interface allows for a default implementation, and this default method is a value for all implementation classes of the implied
Realize.
13. Interfaces and implementation classes are named with two sets of rules:
1 "coercion" for service and DAO classes, based on the SOA concept, the exposed services must be interfaces, internal
The implementation class uses the Impl suffix and the interface difference.
In the positive example: Cacheserviceimpl implements the Cacheservice interface.
2 km /
Alibaba Java Development Manual
2 "Recommended" if it is the description of the interface name of the ability to take the corresponding adjective to do interface name (usually –able shape
Type).
Positive example: Abstracttranslator realizes translatable.
14. The "Reference" enumeration class name is recommended with the enum suffix, the enumeration member names need to be all uppercase, and the words are separated by an underscore.
Description: Enumerations are actually special constant classes, and the constructor method is private by default.
Positive Example: enumeration name: Dealstatusenum; member name: Success/unkown_reason.
15. Naming conventions for "reference":
A) Service/dao layer method naming protocol
1 The method of obtaining a single object is prefixed with get.
2 The method of obtaining multiple objects is prefixed with list.
3 The method of obtaining the statistic value is prefixed with count.
4 the insertion method is prefixed with save (recommended) or insert.
5 The method of deletion is prefixed with remove (recommended) or delete.
6) The modified method is prefixed with update.
(B) domain model naming conventions
1 data object: XXXDO,XXX is the data table name.
2 Data Transfer object: Xxxdto,xxx is the name of the business domain.
3) Display object: Xxxvo,xxx is generally the name of the Web page.
4) Pojo is a general designation of DO/DTO/BO/VO, which is forbidden to be named Xxxpojo.
(ii) Constant definition
1. "Force" does not allow any magical value (that is, undefined constants) to appear directly in your code.