search
HomeJavajavaTutorialDetailed explanation of Java code comment specifications (power node organization)

CodeComments is a communication bridge between program designers and program readers, maximizing the efficiency of team development cooperation. It is also one of the important aspects of program code maintainability. Let’s talk about the code comment specifications we use in daily development through this article

Code comments are a communication bridge between program designers and program readers, maximizing the efficiency of team development cooperation. It is also one of the important aspects of program code maintainability. So we don't write comments for the sake of writing comments. Let’s talk about the code comment specifications we use in daily development for your reference.

1. Uniform comment form

Construct comments using a style with consistent punctuation and structure throughout the application. If you find that their annotation specifications in other projects are different from this document, write code according to this specification and do not try to introduce new specifications into the established specification system.

2. The annotation content should be accurate and concise

The content should be simple, clear, and accurate in meaning to prevent ambiguity in the annotation. Wrong annotation It is not helpful but harmful.

Comment conditions:

1. Basic comments

(a) Class (Interface) Comments

(b) ConstructorComments

(c) Method comments

(d) GlobalComments for variables

(e) Comments for fields/attributes

Note: Simple comments should be made for simple codes, and the comment content should not exceed 10 words. That's it. In addition, the getter and setter methods of the persistent object or VO object do not need to be annotated. Please refer to the example below for the specific comment format.

2. Special comments must be added

(a) Typical algorithms must have comments.

(b) There must be comments where the code is unclear.

(c) Add a comment indicating the modification to the code modification.

(d) Add comments in the code consisting of loop and logical branches.

(e) The interface provided for others must be commented in detail.

Note: There are no examples of this type of comment format yet. The specific annotation format is defined by yourself, and the annotation content is required to be accurate and concise.

Comment format:

1. Single-line comment: “//……”

2. Block comment: “/*&*/”

3. Document comment: “/**&*/”

4. Javadoc comment tag syntax

@author The description of the class indicates the author who developed the module of this type
@version The description of the class indicates the version of the module of this type
@see The description of the class, attributes, and methods refers to the steering. That is, related topics
@param Description of the method Description of a parameter in the method
@return Description of the method Description of the return value of the method
@exception Description of the method Describes the exceptions that may be thrown by the method

Reference example:

1. Class (interface ) Comment

For example:

/**
* 类的描述
* @author Administrator
* @Time 2016-11-14:49:01
*
*/
public classTest extends Button {
 ……
}

2. Construction method Comment

For example:

public class Test extends Button {
 /**
 * 构造方法 的描述
 * @param name
 * 按钮的上显示的文字
 */
 public Test(String name){
 ……
 }
}

3. Method comment

For example

public class Test extends Button {
 /**
 * 为按钮添加颜色
 *@param color
  按钮的颜色
*@return
*@exception (方法有异常的话加)
* @author Administrator
* @Time2012-11-20 15:02:29
 */
 public voidaddColor(String color){
 ……
 }
}

4. Global variable comment

For example:

public final class String
 implements Java.io.Serializable, Comparable<String>,CharSequence
{
 /** The value is used for characterstorage. */
 private final char value[];
 /** The offset is the first index of thestorage that is used. */
 private final int offset;
 /** The count is the number of charactersin the String. */
 private final int count;
 /** Cache the hash code for the string */
private int hash; // Default to 0
……
}

5. Field/attribute comments

For example:

public class EmailBody implements Serializable{
 private String id;
 private String senderName;//发送人姓名
 private String title;//不能超过120个中文字符
 private String content;//邮件正文
 private String attach;//附件,如果有的话
 private String totalCount;//总发送人数
 private String successCount;//成功发送的人数
 private Integer isDelete;//0不删除 1删除
 private Date createTime;//目前不支持定时 所以创建后即刻发送
 privateSet<EmailList> EmailList;
……
}

In fact, the specifications are set by ourselves. As long as everyone in the team abides by them and unifies the specifications, we will get Good effect, I hope it will be helpful to friends who usually don’t comment.

The above is the detailed content of Detailed explanation of Java code comment specifications (power node organization). For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.