This article transferred from:http://www.javaranger.com/archives/390
In this paper, some specifications of the Java coding process are summarized for reference.
1, the Rational organization of code hierarchy, layered clear:controller,logic,DAO, the third-party interface (including the company interface) calls; Each layer inherits the base class or implements the interface
2, first define the method prototype, and then implement the method body
3, the ideal method, is non-split, the atom of a logical realization, with a clear responsibility
4, the method body does not exceed 70 lines, the class body does not exceed 500 lines
5, class name, variable name, method name, follow simple and clear, well-known principles of righteousness. It is recommended that no numbers, underscores and other special characters (except class constants), use meaningful nouns or name combinations, and verb structures (against pinyin naming)
6, the constant name capital
7. There are blank lines between the code logic blocks, the equals sign, the operation symbol, and the variables are left blank
8, loop, conditional statement nesting not more than 2 layers (the best way to avoid nesting is to return early, merge conditions, using sub-methods)
9, the class comment describes the responsibility, the variable must have the explicit annotation, the method annotation describes the duty, the input, the output must have the explanation, the complex logical fragment, must have the explanation;
10, the key points to have the log; Remember that the production environment is an info level;Debug logs must first determine the setting level; The log does not allow sensitive information such as user passwords, accounts, etc., and the use of System.out is prohibited .
11. No more than 4 method parameters
12.The Boolean variable uses the is prefix; method names that return Boolean types use the is prefix
13, the maximum reuse, the same code fragment appears only once, the same semantic variables only define a
14.If judgment logic is too complex, it must be separately practiced as a method
15, the boundary conditions must be processed
16. Exception handling, recommended try. Catch, oppose throw; for caught exception information, the exception stack must be printed out, minimizing the code range of the try
17. Prohibit hard coding of test data
18, prohibit the storage of commented out code
19, configuration items to write the configuration file, against hard-coded
20, can not modify the variable to be final, cannot be rewritten method to add final
21, the database connection, must use the connection pool
22.IO operation (file,URL,db, etc.), keep in mind the close in the finally statement
23, against the indefinitely, against the use of the introduction of new technology
24, the automated test case to meet the order requirements
25. Encourage the use of design patterns
Java encoding Specification (RPM)