Javadoc for a class, a driver, a computation method, a test-case method, and an instance variable.
Include the following bits of data in your Javadoc comment for every class:
Be sure to add Javadoc comments to the class itself as normal.
Then add a Javadoc comment to main():
@return or @param
tags (unless you're using the args parameter).Example:
/**
* This driver reads in a number and squares it. Input (keyboard): an
* integer; output (screen): the integer squared.
*/
public static void main(String[] args) {
Keyboard theKeyboard = new Keyboard();
Screen theScreen = new Screen();
theScreen.print("Enter an integer: ");
int number = theKeyboard.readInt();
theScreen.println(number + " squared is " + (number*number) + ".");
}
Be sure to add Javadoc comments to the class itself as normal. Then add a Javadoc comment to the method:
@param tags.@return
tag.@throws
tag.Example:
/**
* This method squares a number. The square is returned.
* Precondition: the value received must be positive.
* @param n the number to be squared.
* @return the square of the number.
* @throws IllegalArgumentException when the parameter is negative.
*/
public int square(int n) {
if (n < 0)
throw new IllegalArgumentException(n + " is negative.");
return n*n;
}
Example:
/**
* This method tests @link SillyMath#square(int).
*/
public void testSquare() {
assertEquals(9, SillyMath.square(3));
...
}
Example:
/** * The x-coordinate of a point. */ private double myX;