Java Programming specification

Source: Internet
Author: User

The execution statement for the 1.IF for while statement, regardless of how many are added {}

2. There must be a blank line between the relatively independent blocks of the program.

publicvoidfun(int i) {    System.out.println(i);}int index;

3. Snap to use the SPACEBAR only without the TAB key (because the number of different editors tab spaces may be different)

4. In the case of more than two keywords, variables, constants for peer operation, the operator between them before and after the degree of space needs to be added.

5. Separate the comment from the code above with a blank line

6. Definitions of variables and branching statements (conditional branching, looping statements, and so on) must be annotated.

7. Write the code side comment, modify the code while modifying the corresponding comments, to ensure that the comments and code consistency. The useless comment is to be erased.

8. Avoid using abbreviations in annotations, and abbreviations should be explained as necessary when using abbreviations.

9. The property name and method name cannot be the same, both use hump format, and the method name is best used in the verb structure, or verbs.

10. The constant name uses all uppercase, the English word uses the underscore to separate

11. The attribute name containing the set meaning, as far as possible contains the meaning of its plural.

12. All data classes must overload the ToString () method to return content that is meaningful to that class.

13. Define the method function, precisely implement the method design, a function only completes a function, even if the simple function also should write the method implementation. This can increase the readability of the program.

14. Define the functions of the class and precisely implement the design of the class. A class implements only a set of similar functions. (Note: When dividing the class, we should try to separate the logical processing, the data and the display, and realize the uniqueness of the class function.) )
The data class does not contain data processing logic, and the communication class does not contain the logic to display processing.

15. After an exception is captured, the log should be logged if the exception is not processed.

16. The exception you throw must fill in the detailed description information.

17. Avoid the use of difficult-to-understand figures, with meaningful logos instead. Constants that involve physical states or that contain physical meanings should not be used directly, and must be replaced with meaningful static variables.

18. Use int[] array when declaring arrays, instead of using int array[]. Readability issues

19. When debugging code, do not print with System.out or system.err, you should use a test class that contains a unified switch for unified printing.
Description: When the code is released, the debugging code can be closed uniformly, and the switch can be opened when the problem is fixed.

20. Record the exception do not save Exception.getmessage (), but to record exception.tostring ().

21. A method should not throw too many types of exceptions

Description: If classification processing is required in the program, the exception is organized into an inheritance relationship according to the classification. If there are many exception types that first consider the exception description, the Throws/exception clause should best not exceed three exceptions.

22. Exception capture try not to direct catch (Exception e), the exception should be broken down processing

23. If multiple pieces of code do the same thing over and over again, there may be a problem with the partitioning of the method.

Note: If there is a substantial correlation between the statements in this code and the same function is completed, then consider creating a new method of this code.

24. Place the main () method at the end of the class, and declare the method violation without using exception, and use his subclass.

25. Do not throw an error directly, it should be thrown out of its subclass.

26. Try not to use internal classes

27. When using multiple tables for an SQL statement, remember to use aliases, and the fields remember to call the following with the table name

User.password

28.Import do not use wildcard characters: do not appear similar to import statements: Import java.util.*;

29. Sorting of Classes

The order of the members of a class has a great impact on usability, but there is no single universal rule. The ordering of members may be different for different classes. Most importantly, each class should sort its members with some logic, and the maintainer should be able to interpret the sort logic. For example, a new method cannot always be habitually added to the end of a class, because it is ordered in chronological order rather than some sort of logic.
When a class has more than one constructor, or multiple methods with the same name, these functions/methods should appear in order, not in the middle of other functions/methods.

30. Declare a variable each time: Do not use combination declarations, such as int a, b;.

31. The brackets are part of the type: string[] args, not String args[].

32. A blank square before the curly braces, with a space after the conditional statement if while

33.Static in front of final

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java Programming specification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.