Instructions: Follow the steps given in each section below. For each question, click the radio button next to the most correct answer. When you are finished, type your name and your password at the end of the document, print a copy for your records, then press the Submit button. You may submit just one lab response. If you submit more than one, only the first one counts for a grade.
The purpose of this lab is to learn how to automatically generate documentation from a Java program. By the end of this lab, you should be able to put documentation comments in your programs so that javadoc can automatically generate documentation for you.
Note: This lab assumes use of javadoc from Sun's JDK 1.4.1.
// Demonstration of how to use stacks in a program import java.util.Stack; // Our own stack class, uses a fixed-sized array, no error-checking class ArrayStack { public boolean empty() { return top == 0; } public void push(Object value) { data[top] = value; top++; } public Object pop() { top--; return data[top]; } public Object peek() { return data[top]; } private int top = 0; private Object[] data = new Object[100]; } public class DemonstrateArrayStack { // Test the stack classes public static void main(String[] args) { // Here's how to use the ArrayStack class ... ArrayStack myStack = new ArrayStack(); myStack.push("Hello"); myStack.push(new Character('x')); myStack.push(new Integer(123)); myStack.push(new Double(3.45)); System.out.print(myStack.pop() + " "); System.out.print(myStack.pop() + " "); char character = ((Character) myStack.pop()).charValue(); System.out.print(character + " "); System.out.print(myStack.pop() + " "); // ... and here's how to use Java's standard Stack class // (it's almost exactly the same) Stack javaStack = new Stack(); javaStack.push("Hello"); javaStack.push(new Character('x')); javaStack.push(new Integer(123)); javaStack.push(new Double(3.45)); System.out.print(javaStack.pop() + " "); System.out.print(javaStack.pop() + " "); character = ((Character) javaStack.pop()).charValue(); System.out.print(character + " "); System.out.println(javaStack.pop()); } }
javadoc DemonstrateArrayStack.java
javadoc -private DemonstrateArrayStack.java
/** * This is a javadoc comment. * It is on two lines. */
// Demonstration of how to use stacks in a program import java.util.Stack; /** * Our own stack class, uses a fixed-sized array, no error-checking */ class ArrayStack { // ...
import java.util.Stack;
/** * Our own stack class, uses a fixed-sized array, no error-checking */ class ArrayStack { // ...
class ArrayStack { /** * Tells whether the stack is empty */ public boolean empty() { return top == 0; }
class ArrayStack { /** * Tells whether the stack is empty * @return true if the stack is empty, false otherwise */ public boolean empty() { return top == 0; }
/** * Puts the given value on the top of the stack * @param value The object to push on the stack (can be any object) */ public void push(Object value) { data[top] = value; top++; }
/** * Adds two numbers together * @param firstValue The first value to add * @param secondValue The second value to add * @return The sum of the two parameters, as an integer */ public int add(int firstValue, int secondValue) { return firstValue + secondValue; }
For more information about javadoc, visit Sun's home page at http://www.sun.com.
Write down your answers for your records, then press the Submit button below to turn in the lab assignment.