Javadoc is a Java tool that generates API reference documentation automatically from properly formatted, in-line documentation.

Writing JavaDoc Documentation

JavaDoc assembles its documentation by collecting appropriately formatted comments in your code. You can document classes, instance variables and methods using the standard following format illustrated here:

package edu.calvin.cs108;

/** Container.java computes the volume and surface area of cylinders.
 * 
 * @author Keith Vander Linden
 * @version 19june2006
 */
public class Container {

   /**
    * computeVolume computes the volume of a cylinder given common units.
    * 
    * @param diameter	The non-negative diameter of the cylinder
    * @param height	The non-negative height of the cylinder
    * @return volume of the cylinder
    * @see Container#computeArea
    */
   public static double computeVolume(double diameter, double height) {
      return Math.PI * Math.pow(diameter / 2, 2) * height;
   }

   // other methods and documentation...
}

Some Java IDEs, including Eclipse, will automatically format your JavaDoc comments if you type /** and then hit enter just before your class or method definition.

Automatically Assembling JavaDoc Documentation

You can get Eclipse to generate JavaDoc-formatted documentation as follows:

  1. Use the mouse to select the Class file or package you would like to document. For a class library, you will select the class(or classes) you would like to document.
  2. Choose “Project”-“Generate Javadoc...”.
  3. In the dialog box that pops up, make sure that:
    1. the appropriate packages/classes are selected in the directory structure shown at the top
    2. the “Use Standard Doclet” option is selected and that there is a good destination specified for the documentation (e.g., ~/workspace/processing/doc).
  4. Press “Finish”.

This should create a new doc package in your Eclipse workspace in the location specified above.

Viewing JavaDoc Documentation

JavaDoc produces its documentation as a set of HTML-formated API reference documents, which can be viewed using a standard web browser. You can use Eclipse's built-in web-browser to view this documentation as follows:

  1. Click mouse-right on index.html file, the main API documentation file in the doc folder.
  2. Choose “Open with”-“Web Browser”.

A web-browser-like window will open (either as a separate window or directly in Eclipse, depending upon how your Eclipse environment is configured). Use this browser to navigate around the API documentation structure.