4.Java 文档注释的内容,支持采用HTML语法规则书写,同时也支持一些额外的辅助标签
package java.util; /** * This class contains various methods for manipulating arrays (such as * sorting and searching). This class also contains a static factory * that allows arrays to be viewed as lists. * * <p>The documentation for the methods contained in this class includes * briefs description of the <i>implementations</i>. Such descriptions should * be regarded as <i>implementation notes</i>, rather than parts of the * <i>specification</i>. Implementors should feel free to substitute other * algorithms, so long as the specification itself is adhered to. (For * example, the algorithm used by {@code sort(Object[])} does not have to be * a MergeSort, but it does have to be <i>stable</i>.) * * <p>This class is a member of the * <a href="{@docRoot}/../technotes/guides/collections/index.html"> * Java Collections Framework</a>. * * @author Josh Bloch * @author Neal Gafter * @author John Rose * @since 1.2 */ public class Arrays { /** * Sorts the specified array into ascending numerical order. * * <p>Implementation note: The sorting algorithm is a Dual-Pivot Quicksort * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm * offers O(n log(n)) performance on many data sets that cause other * quicksorts to degrade to quadratic performance, and is typically * faster than traditional (one-pivot) Quicksort implementations. * * @param a the array to be sorted */ public static void sort(int[] a) { DualPivotQuicksort.sort(a, 0, a.length - 1, null, 0, 0); } }三、文档标签总结
/** * @author xxxx * @author xxx@123.com * @author <a href="mailto:xxx@123.com">xxxxx</a> */@since
/** * @since 1.4 * @since 15 April 2001 * @since JDK1.5 */@version
/** * @version 1.8.3.4 */@code
/** * xxxx,{@code int var = 1;}xxxx */@return
/** * @return <code>true</code> 执行成功;<code>false</code> 执行失败. */@param
/** * @param img the image to be drawn */@value
/** * Default start value. {@value #START_VALUE} */@throws 和 @exception
/** * @throws IllegalArgumentException * if {@code fromIndex > toIndex} */@link 、@linkplain 和 @see
/** * xxx {@link java.lang.String#charAt(int)} * xxx {@link #sort(Object[])} * xxx {@linkplain Comparable natural ordering} * @see #deepHashCode(Object[]) */@inheritDoc
/** * {@inheritDoc} * <p> * The speed of tiger will be returned. * * @return the speed of tiger */@deprecated
/** * @deprecated As of JDK 1.1, replaced by * {@link #setBounds(int, int, int, int)} */@serial
/** * @serial description */@serialData
/** * @serialData description */@serialField
/** * @serialField name type description */最后,在使用文档注释时,通常会按照如下顺序进行使用。
@deprecated
javadoc -d 文档存放目录 -author -version 源文件名.java这条命令编译一个名为源文件名.java的 java 源文件,并将生成的文档存放在文档存放目录指定的目录下,生成的文档中index.html就是文档的首页。
/** * 这个类演示了文档注释 * 堆代码 duidaima.com * @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 like. * * @param num The value to be squared. * @return num squared. */ public double square(double num) { return num * num; } /** * This method inputs a number from the user. * * @return The value input as a double. * @throws 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. * @throws IOException On input error. * @see IOException */ public static void main(String args[]) throws IOException { SquareNum ob = new SquareNum(); double val; System.out.println("Enter value to be squared: "); val = ob.getNumber(); val = ob.square(val); System.out.println("Squared value is " + val); } }使用 javadoc 工具处理 SquareNum.java 文件,生成 javadoc api 文档,在命令行输入如下命令,即可实现文档的生成!
javadoc SquareNum.java四、小结