Java Documentation Comments

Source: Internet
Author: User
Tags deprecated return tag

Ava Documentation Notes

Java supports three kinds of annotation methods. The first two are//and /*/, and the third is called the Explanatory Note, whichstarts with/* and ends with */.

The description comment allows you to embed information about the program in your program. You can use the Javadoc tool software to generate information and output it to an HTML file.

Explanatory notes that make it easier for you to record your program information. Javadoc label

The

Javadoc tool software identifies the following tags: Label description example @author identifies the author of a class @author description@deprecated named an expired class or member @deprecated description{@ Docroot} indicates the path to the root directory of the current document directory Path@exception flags an exception thrown by a class @exception exception-name explanation{@inheritDoc} Comments inherited from the immediate parent class Inherits a comment from the immediate surperclass. {@link} inserts a link to another topic {@link name text}{@linkplain} inserts a link to another topic, but the link displays a plain text font inserts an in-line link to another topic.@p Aram describes the parameters of a method @param parameter-name Explanation@return describes the return value type @return explanation@see specifies a link to another topic @see anchor@serial Describes a serialization property @serial Description@serialdata describes data written through the WriteObject () and Writeexternal () methods @serialData Description@serialfield describes a Objectstreamfield component @serialField the name Type description@since tag when a specific change is introduced @since Release@throws is the same as @exception tag. The @throws tag has the same meaning as the @exception tag. {@value} Displays the value of the constant, which must be a static property. Displays the value of a constant, which must be a static field. @version the version of the specified class @version info document comment

After the beginning of the/**, the first row or lines are the main descriptions of the classes, variables, and methods.

After that, you can include one or more kinds of @ tags. Each @ tag must be at the beginning of a new line or at the beginning of a line followed by an asterisk (*).

Multiple labels of the same type should be placed in a group. For example, if you have three @see tags, you can put them together one after the other.

The following is an example of a description comment for a class:/*** This class draws a bar chart

    • @author Runoob
    • What @version 1.2*/javadoc output

The Javadoc tool takes the source code of your Java program as input and outputs some HTML files that contain comments from your program.

The information for each class will be in its own HTML file. Javadoc can also output inherited tree structures and indexes.

Because the Javadoc implementation is different, the work may be different, you need to check the version of your Java development system and other details, select the appropriate Javadoc version. Instance

The following is a simple example of using explanatory notes. Note that each comment is in front of the item it describes.

After Javadoc processing, the comments for the Squarenum class are found in the squarenum.html. Squarenum.java file code: Import java.io.*;

/**

  • This class demonstrates the documentation comments
  • @author Ayan amhed
  • @version 1.2/public class Squarenum {/*
    • This method returns the square of Num.
    • This is a multiline description. You can use
    • As many lines as you.
    • @param num The value to be squared.
    • @return Num Squared. /public double square (double num) {return num * num;} /*
    • This method is inputs a number from the user.
    • @return the value input as a double.
    • @exception IOException on input error.
    • @see IOException/public Double GetNumber () throws IOException {InputStreamReader ISR = new InputStreamReader ( system.in); BufferedReader inData = new BufferedReader (ISR); String str;str = Indata.readline (); return (new Double (str)). Doublevalue (); /*
    • This method demonstrates square ().
    • @param args Unused.
    • @return nothing.
    • @exception IOException on input error.
    • @see ioexception*/public static void Main (String args[]) throws Ioexception{squarenum ob = new Squarenum ();d ouble Val; System.out.println ("Enter value to be squared:"); val = Ob.getnumber (); val = Ob.square (val); System.out.println ("squared value is" + val);}}

as follows, use the Javadoc tool to process the Squarenum.java file:

$ javadoc squarenum.javaloading source file Squarenum.java ... Constructing Javadoc information ... Standard Doclet version 1.5.0_13building tree for all the packages and classes ... Generating squarenum.html ... squarenum.java:39:warning-@return tag cannot be used
In method with void return type. Generating package-frame.html ... Generating package-summary.html ... Generating package-tree.html ... Generating constant-values.html ... Building index for all the packages and classes ... Generating overview-tree.html ... Generating index-all.html ... Generating deprecated-list.html ... Building index for all classes ... Generating allclasses-frame.html ... Generating allclasses-noframe.html ... Generating index.html ... Generating help-doc.html ... Generating stylesheet.css ... 1 warning$

Java Documentation Comments

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.