This article is divided into two parts: comments (Basic) and annotations (advanced). In the Comments (Basic) Section , mainly about the concept of annotations, categories, write the specification of comments, details and role; in the Notes (Advanced) Section , we mainly use the Javadoc development tool to generate a developer's documentation.
Content Overview:
-
The concept of annotations
-
Categories of annotations
-
Specifications for writing annotations
-
Notes to note the details
-
The role of annotations
Notes Advanced
-
The difference between a document comment and a multiline comment: developer documentation
-
Generate a developer document using the Javadoc development tool
1. Notes (Basic)
1.1, the concept of annotations
A note is a description of the program using text, which is written to programmers, and the compiler ignores the contents of the comment.
1.2. Categories of annotations
First: Single-line comments. The content of the comment
Second: Multiple lines of comment. /* Contents of comments */
The third type: document comments. The contents of the/** comment */Document comment is also a multiline comment.
1.3, write the specification of the annotation
General single-line comments are located on the right side of the code, and multiple lines of comments and documentation comments are generally written on top of the class or method.
1.4. Notes to note the details
Single-line comments can be nested, and multiline comments cannot be nested
1.5, the role of annotations
1. Use Text to program description
2. Debugger: Sometimes the program is more complex, you need to comment out some of the content, to help find the wrong place
2. Notes (Advanced)
There is a saying that
Software = data + instruction + documentation (user documentation + developer documentation)
That is, the software consists of data, directives, and documents, and the documentation includes user documentation and developer documentation. The developer documentation can be generated from the documentation annotations and Javadoc tools in the Java language.
2.1. The difference between a document comment and a multiline comment: developer documentation
The contents of a multiline comment cannot be used to generate a developer document, and the content of a document comment can produce a developer document.
2.2. Generate a developer document using the Javadoc development tool
2.2.1, Javadoc tool use Format
javadoc-d source file for the path to the document stored in Java
2.2.2, use Javadoc tools to pay attention to the details
1. If a class needs to use the Javadoc tool to generate a developer document for a software, the class must be decorated with public.
2. The contents of a document comment note are generally located above the class or method.
2.2.3, author, and version information
Add "@author xxx classmate" and "@version 1.0" to the documentation comments in the source code
When using the Javadoc tool, use the following command:
javadoc-author-version-d source file for the path to the document stored in Java
2.3. Practical operation
Under the D:\rk folder, create a new Mytest.java file with the following contents:
/** This is one of my test classes * @author RK * @version 1.0 */public Class mytest{/** * Here is the MyTest class's entry function main * @param args this is the parameter to be entered */public stat IC void Main (string[] args) {System.out.println ("Hello world!");}}
In the console, switch to the D:\RK directory and use the following command:
javadoc-author-version-d D:\rk\mydoc Mytest.java
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7E/D3/wKiom1cJR9jQa5RnAABKmIyZrZk087.png "title=" Javadoc_author_version.png "alt=" Wkiom1cjr9jqa5rnaabkmiyzrzk087.png "/>
View results:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7E/D0/wKioL1cJSUOR4QcpAADTLqyERfQ704.png "style=" float: none; "title=" Open_index_html.png "alt=" Wkiol1cjsuor4qcpaadtlqyerfq704.png "/>
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7E/D0/wKioL1cJSUPjBwclAABWxZL8u_8178.png "style=" float: none; "title=" Mydoc_part1.png "alt=" Wkiol1cjsupjbwclaabwxzl8u_8178.png "/>
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7E/D3/wKiom1cJSJLj5jMLAAA18LjKtew181.png "style=" float: none; "title=" Mydoc_part2.png "alt=" Wkiom1cjsjlj5jmlaaa18ljktew181.png "/>
Mind Mapping
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7E/D3/wKiom1cJSSOjVYORAACcxEmnfXQ680.png "title=" Java comment. png "alt=" Wkiom1cjssojvyoraaccxemnfxq680.png "/>
If you encounter exception in thread main Java.lang.NoClassDefFoundError, this may be the three reasons: 1, the class name (capitalization problem), 2, the package name (whether in the package) and 3, Classpath set problems.
Java Annotations and Javadoc tools