Java – Documentation Comments

The Java language supports three types of comments:

  • /* text */ – The compiler ignores everything from /* to */.
  • //text – The compiler ignores everything from // to the end of the line.
  • /** documentation */ – This is a documentation comment and in general its called doc comment. The JDK javadoc tool uses doc comments when preparing automatically generated documentation.

What is Javadoc?

Javadoc is a tool that comes with JDK and it is used for generating Java code documentation in HTML format from Java source code, which requires documentation in a predefined format.

Following is a simple example where the lines inside /*….*/ are Java multi-line comments. Similarly, the line that precedes // is Java single-line comment.

Example:

/**
* The HelloWorld program implements an application that
* simply displays "Hello World!" to the standard output.
*
* @author  Singh is king
* @version 1.0
* @since   2018-02-12
*/public class HelloWorld {

   public static void main(String[] args) {
      /* Prints Hello, World! on standard output.
      System.out.println("Hello World!");
   }
}

Following example makes use of * for heading and has been used for creating paragraph break:

Example:

/**
* <h1>Hello, World!</h1>
* The HelloWorld program implements an application that
* simply displays "Hello World!" to the standard output.
* <p>
* Giving proper comments in your program makes it more
* user friendly and it is assumed as a high quality code.
*
*
* @author  Singh is King
* @version 1.0
* @since   2018-03-12
*/public class HelloWorld {

    public static void main(String[] args) {
        /* Prints Hello, World! on standard output.
        System.out.println("Hello World!");
    }
}
Related Post