Chapter 22: Javadoc

The exercises here are taken from my forthcoming book, The Java Developer's Resource.

Quiz

  1. What's the difference between a doc comment and a regular comment?

    As far as the compiler is concerned, there is no difference. As far as the programmer is concerned doc comments begin with /** and regular comments begin with /*. Doc comments are automatically parsed out by javadoc.

Exercises

  1. Use javadoc to document the treenode class in Program 21.6 of last chapter.

    
    /**
     * This class represents a node of a binary tree.
     * @version 1.0 of August 26, 1996 
     * @author Elliotte Rusty Harold 
     */
    public class treenode {
    
      double data;
    
      treenode left;
      treenode right;
    
      /**
       * Creates a new node with the value d
       * @param d The number to be stored in the node
       */
      public treenode (double d) {
        data = d;
        left = null;
        right = null;
      }
      
      /**
       * This method stores a double in the tree by adding a new node
       * with the value d below the current node.
       * @param d The number to be stored in the tree
       */
      public void store (double d) {
        if (d <= data) {
          if (left == null) left = new treenode(d);
          else left.store(d);
        }
        else {
          if (right == null) right = new treenode(d);
          else right.store(d);
        }
      }
      
       /**
       * This method prints this node on System.out.
       */
      public void print() {
      
        if (left != null) left.print();
        System.out.println(data);
        if (right != null) right.print();
      
      }
      
    }
    


[ Exercises | Cafe Au Lait | Books | Trade Shows | Links | FAQ | Tutorial | User Groups ]

Copyright 1996 Elliotte Rusty Harold
elharo@sunsite.unc.edu
Last Modified September 5, 1996