Java Comments
In computer languages, comments are an important part of the language. They are used to explain the purpose of code in the source code, which can enhance the readability and maintainability of the program.
Java comments are text used in Java programs to provide explanations of code functionality.
Comments are not included by the compiler in the final executable program, so they do not affect the program's operation.
Comments are a good programming habit. They help programmers understand the purpose and functionality of the code more easily, and are very useful in team collaboration.
Java comments mainly have three types:
- Single-line comments
- Multi-line comments
- Documentation comments
Single-line comments
Single-line comments start with a double slash//start:Example
Multi-line comments
Multi-line comments start with/*start, and end with*/end:
Example
Documentation comments
Documentation comments start with/**start, and end with*/end. They usually appear before declarations of classes, methods, fields, etc., to generate code documentation. Such comments can be extracted by tools to generate API documentation, such as JavaDoc.
Example
The format of documentation comments usually contains specific tags, such as@paramused to describe method parameters,@returnused to describe return values,@throwsused to describe exceptions that may be thrown, etc. These tags help generate clear API documentation so that other developers can better understand and use your code.
For more content on documentation comments, refer to:Java Documentation Comments。
Other Extensions