Java API文档生成器

以下程序使用了一些可用于文档注释的重要标签。您可以根据需要使用其他标签。

有关AddNum类的文档将在HTML文件AddNum.html中生成,但同时,还将创建一个名称为index.html的主文件。

import java.io.*;
/**
  * <h1>Add Two Numbers!</h1>
  * The AddNum program implements an application that
  * simply adds two given integer numbers and Prints
  * the output on the screen.
  * <p>
  * <b>Note:</b> Giving proper comments in your program makes it more
  * user friendly and it is assumed as a high quality code.
  * </p>
  * @author Zara Ali
  * @version 1.0
  * @since 2014-03-31
  */

public class AddNum {
   /**
     * This method is used to add two integers. This is
     * a the simplest form of a class method, just to
     * show the usage of various javadoc Tags.
     * @param numA This is the first paramter to addNum method
     * @param numB This is the second parameter to addNum method
     * @return int This returns sum of numA and numB.
     */
   
   public int addNum(int numA, int numB) {
      return numA + numB;
   }
   /**
    * This is the main method which makes use of addNum method.
    * @param args Unused.
    * @return Nothing.
    * @exception IOException On input error.
    * @see IOException
    */

   public static void main(String args[]) throws IOException {
      AddNum obj = new AddNum();
      int sum = obj.addNum(10, 20);
      System.out.println("10和20的总和是:" + sum);
   }
}

现在,使用Javadoc实用程序处理上述AddNum.java文件,如下所示-

$ javadoc AddNum.java
Loading source file AddNum.java...
Constructing Javadoc information...
Standard Doclet version 1.7.0_51
Building tree for all the packages and classes...
Generating /AddNum.html...
AddNum.java:36: 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...
1 warning
$