CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ | Grades

Packages

Packages
javadoc
Add comments

By including documentation comments in your own classes, you can generate HTML documents, complete with hyperlinks and readable through a browser, that describe your own classes and methods.

How to add javadoc comments to a class

  • A javadoc comment begins with /** and ends with */, and asterisks within the comment are ignored.
  • You can use javadoc comments to describe a class and the public and protected fields, constructors, and methods it contains.
  • A comment should be placed immediately above the class or member it describes. For a class, that means that the comment must be placed after any import statements.

The Product class with javadoc comments

package murach.business;

import java.text.NumberFormat;

/**********************************************************
 * The Product class represents a product and is used by
 * the LineItem and ProductDB classes.
 **********************************************************/
public class Product
{
    private String code;
    private String description;
    private double price;

    /***********************************************************
     * Creates a new Product with default values.
     ***********************************************************/
    public Product()
    {
        code = "";
        description = "";
        price = 0;
    }

    /***********************************************************
     * Sets the product code to the specified String.
     ***********************************************************/
    public void setCode(String code)
    {
        this.code = code;
    }

    /***********************************************************
     * Returns a String that represents the product code.
     ***********************************************************/
    public String getCode(){
        return code;
    }
    .
    .
    .
Previous | Add comments | use HTML | Generate documentation | View documentation | Next