Java documentation annotation-javadoc usage, java annotation-javadoc

Source: Internet
Author: User

Java documentation annotation-javadoc usage, java annotation-javadoc

1. Preface

Java has three annotation methods. The first two are://And/**/It is mainly used for code comments to facilitate code readability. The third type is called description annotation or document annotation. It uses/**Start*/End: The document comment allows you to embed information about the program in the program. With this comment, you can use the javadoc tool to generate information and output it to the HTML file.

2. Document comment format

/**
*.........
*.........
*/

In/**The first or several rows are the main descriptions of classes, variables, and methods.

Then, you can include one or more@ Tag. Every@The label must be followed by an asterisk (*) at the beginning of a new line or at the beginning of a line. The commonly used labels are as follows (for detailed labels, see the http://www.runoob.com/java/java-documentation.html ):

Tag Description Example
@ Author Identifies the author of a class @ Author description
@ Version Version of the specified class @ Version info
@ Param Describes the parameters of a method. @ Param parameter-name explanation
@ Return Return Value Type @ Return explanation
     

 

 

 

 

 

The following is an example of a class description annotation:

1/** my array help Class 2 * defines a tool class for operating arrays. 3 * For example, get the most value, sort, and half. 4 * @ author Zhang San 5 * @ version V1.0 6 */7 public class ArrayTool 8 {9 10/** 11 empty parameter constructor of the class. 12 */13 private ArrayTool () {} 14 15/** 16 get the maximum value of the int array. 17 @ param arr is used to receive an array of the int type. 18 @ return returns the maximum value in the array. 19 */20 public static int getMax (int [] arr) 21 {22 int max = arr [0]; 23 for (int x = 1; x <arr. length; x ++) 24 {25 if (arr [x]> max) 26 max = arr [x]; 27} 28 29 return max; 30} 31/** 32: sorts the int array in ascending order. 33 @ param arr is used to receive an array of the int type. 34 */35 public static void bubbleSort (int [] arr) 36 {37} 38}

3. Use javadoc to generate documents

Command: javadoc-d file storage directory-author-version source file name. java

This command compiles a file named "source file name. java "and store the generated documents in the directory specified by" document storage directory ". In the generated documents, index.html is the homepage of the document. -Author and-version options can be omitted.

4. test example

4.1 operation commands

4.2 open index.html under the help folder

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.