Java Code Specification Documentation

Source: Internet
Author: User
Tags deprecated oracle documentation

NOTE : The following sections are a brief coding specification, please refer to the official ORACLE documentation for more specifications .

Address: http://www.oracle.com/technetwork/java/codeconventions-150003.pdf

Also, use UTF-8 format to view the code to avoid garbled Chinese.

As to whether the comments should be in Chinese or English, please make your own decision, according to the requirements of the company or the project, the recommended use of English.

1. Organize your code

1.1. In Java code, warnings that cannot be eliminated are not allowed @SuppressWarnings.

1.2. Remove useless packages, methods, variables, etc. to reduce the zombie code.

1.3. Use the Lint tool to view and dismiss warnings and errors.

1.4. use Ctrl+shift+f to format the code, and then adjust it.

1.5. use Ctrl+shift+o to format the Import package.

2. naming rules

2.1. Basic Principles

2.1.1. variables, methods, class naming to be justified, strictly prohibit the use of name1, name2 and other names.

2.1.2. names cannot be too long, use shorthand or abbreviations appropriately. (preferably not more than three letters)

2.1.3. The method name starts with a lowercase letter, and the first letter of each word is capitalized.

2.1.4. Avoid names that are similar or differ only in case.

2.1.5. Avoid using numbers, but use 2 instead of to, use 4 instead of for, such as Go2clean.

2.2. classes, interfaces

2.2.1. All words are capitalized in the first letter. Use words that respond exactly to the class, the meaning of the interface, the function, and so on. Nouns are generally used.

2.2.2. interface with I prefix, or able, ible,er and other suffixes. such as iseriable.

2.3. fields, constants

2.3.1. member variables start with M, and static variables begin with S, such as Musername, Sinstance.

2.3.2. constants are all uppercase and are underlined before words and words, such as Max_number.

2.3.3. Hard coding is forbidden in the code, and some numbers or strings are defined as common quantities.

2.3.4. for deprecated functions, in order to maintain compatibility, it is common to add @Deprecated, such as {@link #doSomething ()}

3. Notes

Please refer to the {@link #SampleCode} class for comments.

3.1. constant comments, see {@link #ACTION_MAIN}

3.2. variable comments, see {@link #mObject0}

3.3. function comments, see {@link #doSomething (int, float, String)}

4. Class Internal order and logic

4.1. each class should arrange the base member variables, methods, inner classes, etc. according to a certain logical structure.

so as to achieve good readability.

4.2. in general, the arrangement of functions according to public first, post protected, last private,

There should also be a logical order of precedence, from heavy to light.

4.3. The following sequence is available for reference:

define tag, usually private (optional)

define public constants

define protected constants, inner classes

define private variables

Defining The public method

Defining the protected method

define private methods

5. Expressions and statements

5.1. Basic principles: Writing code in a compact style

5.2. rules

5.2.1. conditional expression, see {@link #conditionFun (Boolean)}

5.2.2. Switch statement, see {@link #switchFun (int)}

5.2.3. Looping statements, see {@link #circulationfun (Boolean)}

5.2.4. Errors and exceptions, see {@link #exceptionFun ()}

5.2.5. Miscellaneous, see {@link #otherFun ()}

5.2.6. annotations, see {@link #doSomething (int, float, String)}

Java Code Specification Documentation

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.