CS1027b Computer Science Fundamentals II

Javadoc

Javadoc is a tool to help produce documentation of Java classes. Javadoc is a standard for documenting the author of the code, method parameters and method return values, classes and instance variables.

For a complete description of the Javadoc tool, see the Javadoc Tool documentation in the Oracle webpage. This link is given for your reference only, as there is far too much information in that web page for our purposes.

Javadoc Comments

Javadoc Tags

Javadoc tags are used within the javadoc comments for documenting specific parts of a class or method. These tags must appear at the beginning of a line. Here are the most common Javadoc tags:

Example

/**
 * This class represents a rectangle. Each rectangle has a specific length and width.
 * @author CS1027 Lecture Notes
 */
 
public class Rectangle {
 
/**
 * Length of the rectangle
 */
  private int length;
/**
 * Width of the rectangle
 */
  private int width;
 
/**
 * Constructor creates a rectangle with the given length and width
 * @param len length of the rectangle
 * @param wid width of the rectangle
 */
  public Rectangle(int len, int wid) {
    length = len;
    width = wid;
  }
/**
 * Accessor method to get the length of the rectangle
 * @return length of the rectangle
 */
  public int getLength() {
    return length;
  }
}

HTML Tags

Since Javadoc outputs HTML-based documentation, you can also put HTML tags within the comments, such as:

<b>text to be displayed</b> in boldface
<p>the beginning of a new paragraph
Example:
/**
 *  This is a <b>Javadoc</b> comment.
 */

Running Javadoc

In Eclipse, select Project, Generate Javadoc to create the HTML documentation based on the Javadoc comments of all classes within the project. The HTML documentation can be displayed in a browser such as Internet Explorer; index.html is the starting point of the documentation.