This is the 26th day of my participation in the August Text Challenge.More challenges in August

preface

Note is the soul of a file, in our development, often refer to a variety of documents, there will be very detailed notes on the document, some even have examples, so development for so long, will you use document notes? Java document annotations are described below

The initial comments

Annotation function: mainly used to generate description file, for users or readers to quickly familiar with the Settings, but also for their own future to see at a glance.

Single-line comments

  • One-line comment:
  • Symbol [//]
  • Format: // Follow the comment content to comment the content
  • The following is an example:
Public static void main(String[] args) {system.out.println (" 使 用 - 使 用 - 使 用 "); }Copy the code

Multiline comment

  • Multiline comment
  • Symbol [/* */]
  • Format: /* Comment content */
  • The following is an example:
Public static void main(String[] args) {/* System.out.println(" system.out.println "); }Copy the code

Documentation comments

  • Documentation comments
  • Symbol [/***/]
  • Format: It starts with /** and ends with */. Documentation comments are also explanatory comments that allow you to embed information about your program in your program. You can use the Javadoc tools to generate the information and output it to an HTML file.
  • The following is an example:
/** * @description: tests multiple lines of text output * @param * @return: void * @author: JavaZhan @@date: 2020/6/13 **/ Public static void testJavaDoc(){system.out.println ("... "); JavaZhan @@date: 2020/6/13 **/ Public static void testJavaDoc(){system.out.println ("... "); System.out.println("作者 : 小 jack "); System. The out. Println (" homepage address: https://juejin.cn/user/2040300414187416/posts "); System.out.println(" welcome to pay attention to exchange learning! ); }Copy the code

MethodName, @description, @Param, @return, what other tags are there for document annotations besides the tags that appear in articles? Which labels can be used? Here is a summary for you.

Annotate commonly used tags

The label describe The sample
@Author The author of a class or method @author description
@Deprecated An expired class or member @deprecated description
@Date Creation date @Date: 2020/6/13
{@docRoot} Path to the current document root Directory Path
@exception Thrown exception @exception exception-name explanation
{@inheritDoc} Comments inherited from a direct parent class Inherits a comment from the immediate surperclass.
{@link} Insert a link to another topic {@link name javadoc}
{@linkplain} Insert a link to another topic, but the link displays a plain text font Inserts an in-line link to another topic.
@param Method parameters @param parameter-name explanation
@return Return value type @return explanation
@see Specify a link to another topic @see anchor
@serial A serialized property @serial description
@serialData Note Write data using the writeObject() and writeExternal() methods @serialData
@serialField Describes an ObjectStreamField component @serialField name type description
@since Flag when a particular change is introduced @since release
@throws Like the @exception tag, an exception is thrown The @throws tag has the same meaning as the @exception tag.
{@value} Displays the value of a constant, which must be static. Displays the value of a constant, which must be a static field.
@version Specifies the version of the class @version info
@MethodName Method names @MethodName testJavaDoc

After /**, the first line or lines are the main descriptions of classes, variables, and methods. Annotation documents can provide easy-to-read text content for classes, methods, interfaces, enumerations, and so on, based on tags, for developers and users.

Quick start

Generating documentation

This document is generated using Javadoc. Javadoc is a Sun technology that extracts class, method, member, and other comments from a program’s source code to form an API help document that matches the source code. That is, as long as the program is annotated with a specific set of tags, the development documentation of the program can be formed through Javadoc at the same time after the program is written.

The javadoc command is used to generate API documents by entering javadoc + file name. Java in the target file directory on the command line. The command is as follows:

javadoc ****.java
Copy the code

Enter the directory

Enter the file to be generated as shown in the following image: javadoc ****. Java

Execute javadoc tests.java to generate the following files and folders.

Click on index. HTML and you have entered the document page.

conclusion

That’s how Java document comments are generated.

About the author: [Little Ajie] a love tinkering with the program ape, JAVA developers and enthusiasts. Public number [Java full stack architect] maintainer, welcome to pay attention to reading communication.

Well, thank you for reading, I hope you like it, if it is helpful to you, welcome to like collection. If there are shortcomings, welcome comments and corrections. See you next time.