Strengthen individual Java programming specifications

Source: Internet
Author: User

  1. Naming rules

  2. Variable definition
    Use int [] packets, never use int Packets [] format

  3. Code Writing
    We recommend that you use the Unix format -- press ENTER + line feed.
    Javadoc docalization
    Indent 2 characters (do not use tab to avoid setting different tabs for different code management tools)
    No meaningless parentheses are added. {} is divided into two rows.
  4. Global variables should be annotated in detail, including descriptions of their functions, value ranges, which functions or processes access them, and precautions for access.
  5. Annotation Specification
    Three Forms -- // comment a row
    /*...... */Annotate several rows
    /**...... */Document comment, written to javadoc
    Comment on top or right

    The entire source file must be annotated in detail.
     
    Comments necessary before each function

    Javadoc annotation label Syntax:

    @ Author the description of the class indicates the author who developed the class module.

    @ Version the description of the class indicates the version of the class module.

    @ See references to classes, attributes, and methods, that is, related topics

    @ Param: Description of a parameter in the other method

    @ Return description of the method description of the return value of the Method

    @ Exception description of methods to describe possible exceptions thrown by methods

  6. Function
    Make sure that each parameter has a definite meaning.
    Exit can only be called in main
    The top-level Main should capture all exceptions and print them to the screen or record logs.
    If you are not sure whether a certain type of data is inherited, it is not easily defined as final.

  7. * The style that the Java file should follow (mainly including the following parts)

    The version information is placed at the beginning of the Java file, in the form of (other content that cannot be included in javadoc can also be included)

    The package is placed before the import, and the import standard is placed before the import local.

    Class Annotation

    Class Definition

    Class member variables (javadoc must be generated for Public member variables)

    Access Method (you can write it in the same row if it is easy)

    Constructor

    Class Method

    Tostring method (each class should have the tostring method)

    Main method (if there is a main method, it should be written at the bottom of the class)

  8. Pay attention to some performance
    Do not create or release variables in recycling

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.