It is very important for program developers to attach comments to code. With the development of technology, programmers must be required to write code comments during project development, which is conducive to the subsequent writing and use of code.
Basic requirements:
1. Unified comment form
Throughout the application, use styles with consistent punctuation and structure to construct annotations. If you find that their annotation specifications are different from this document in other projects, write code according to this specification and do not attempt to introduce new specifications into the established specification system.
2. The comment content is accurate and concise
The content should be simple, clear and accurate, and the meaning should be prevented from ambiguity of comments. Incorrect comments are not only useless but also harmful.
3. Basic comments (must be added)
(a) Comments for class (interface)
(b) Commentary of the constructor
(c) Comments on methods
(d) Comments of global variables
(e) Notes for fields/attributes: Simple code makes simple comments, the comment content is no more than 10 words, and in addition, persist objects or
The getter and setter methods of VO objects do not need to be commented. For specific annotation formats, please refer to the following examples.
4. Special comments must be added (must be added)
(a) Typical algorithms must be commented.
(b) Comments must be made in unclear code.
(c) Add a comment to the modification mark at the code modification.
(d) Comment in the code composed of loops and logical branches.
(e) The interfaces provided to others must be commented in detail.
Note: There are no examples for this type of comment format. The specific annotation format is defined by yourself, and the annotation content is required to be accurate and concise.
5. Comment format:
1) Single-line comment: "//..."
2) Block comment: "/*…*/"
3) Document comments: "/**…*/"
4) Javadoc comment tag syntax
@author The description of the class indicates the author who developed the module of the class
@version The description of the class indicates the version of the module of the class
@see Reference turn to the description of classes, properties, and methods, that is, related topics
@param Description of method Description of a parameter in a method
@return Description of method Description of method return value
@exception Description of method Description of exceptions that may be thrown by the method
6. Example:
/** Create a tool class for manipulating arrays, which contains this common function for operating arrays: the most value. @author Zhang San@version v. */ public class ArrayTool{ /** Get the maximum value of the shaping array @param arr Receive an array of elements of int type @return The maximum element value of the array */ public int getMax(int arr){ int Max = ; return Max; } }Enter the command as shown below:
Then check it in the following directory and finally click index.html:
The above content shares Java code comment specifications with you, hoping it will be helpful to you.