Using Javadoc to create documentation

Programmers often complain about insufficient documentation yet most of use don't take the time to document our code properly. Javadoc facilitates documentation by allowing coders to write the documentation directly in the code with tags. The documentation is then compiled into user-friendly HTML documentation. There are no hard and fast rules on how to document or what to document. Following is a sample documented code to help you get started.

/**
 * Description of the class
 *
 * @author      your name goes here
 * @version     1.0 or 2011-12-31                   
 */
public class MyClass {
    /**
     * keeps count of whatever
     */
    private int counter;

    /**
     * calculate whatever
     * @param input description
     * @return output description
     */
    public int calculateSomething(int x) {
        // do something
    }
}

The is the bare minimum documentation you should provided; description of the class, version and author information, description of each class variable, description and input and output of each method. All the keyword starting with @ symbol such as @param and @return are called tags. They serve a specific purpose in documentation. For example, @param specifies the parameter taken by the method. There are many other tags and numerous guidelines for documentation listed on the javadoc page.