Java – How to document your code ?

Problem Statement

You need to document your java classes so that it helps in maintenance.


Use Javadoc and place comments before any method , field or class to document.

Just enter /** to start writing the comments using javadoc. The subsequent lines needs to begin with * and end the comment section with */

Below is a sample code demonstrating the usage of the javadoc for the comments.

package abundantcode;


 * @author Abundantcode
public class abundantcodeconsole {
     *  The main method that accepts input from the console and displays it
     * @param args
    public static void main(String[] args) {

        BufferedReader input = new BufferedReader(new InputStreamReader(;
        System.out.println("Enter data");
        try {
            String data = input.readLine();
        catch(Exception ex)

        Boolean b1 = Boolean.valueOf("false");



The specific format defined above lets the developers to generate HTML documentation for the classes using the command-line tool called Javadoc. This tool parses the java source file and generates HTML documentation.

Eg :


You can also pass the complete package to the Javadoc tool instead of the single java file.

javadoc abundantcode