Java documentation comment(Javadoc)

In this chapter you will learn:

  1. What is javadoc for
  2. Syntax for javadoc
  3. Example - Java documentation comment, Javadoc
  4. Javadoc tag list
  5. Example - More javadoc tags

Description

Javadoc Documentation comment is used to produce an HTML file that documents your program. In short we usually call Java documentation comment javadoc.

Syntax

A Javadoc comment occupies one or more lines of source code. The documentation comment begins with a /** and ends with a */. Everything from /** through */ is ignored by the compiler.

Example

The following example demonstrates a Javadoc comment:


/** /*from   www.jav a  2s.  c  om*/
* Application entry point 
* 
* @param args array of command-line arguments passed to this method 
*/ 
public static void main(String[] args) 
{ 
// TODO code application logic here 
}

This example begins with a Javadoc comment that describes the main() method. /** and */ contains a description of the method, which could include HTML tags such as <p>, <code> and /</code>, and the @param Javadoc tag (an @-prefixed instruction).

Tag list

The following list identifies several commonly used tags:

  • @author identifies the source code's author.
  • @deprecated identifies a source code entity that should no longer be used.
  • @param identifies one of a method's parameters.
  • @see provides a see-also reference.
  • @since identifies the software release where the entity first originated.
  • @return identifies the kind of value that the method returns.

Example 2

The following code has more documentation comments


/**//from  ww w. j  ava  2  s  .c o  m
 * A simple class for introducing a Java application.
 * 
 * @author yourName
 */
public class HelloWorld {
  /**
   * Application entry point
   * 
   * @param args
   *          array of command-line arguments passed to this method
   */
  public static void main(String[] args) {
    System.out.println("Hello, world!");
  }
}

We can extract these documentation comments into a set of HTML files by using the JDK's javadoc tool, as follows:

javadoc command defaults to generating HTML-based documentation for public classes and public/protected members of these classes.

Next chapter...

What you will learn in the next chapter:

  1. What are arrays in Java
  2. Java Array Index
  3. Java Array Index Value
Home »
  Java Tutorial »
    Java Langauge »
      Java Statement
Java if Statement
Java if else Statement
Java if else ladder statement
Java nested if statement
Java switch Statement
Java for loop
Java for each loop
Java while Loop
Java do while loop
Java break statement
Java continue statement
Java Comments
Java documentation comment(Javadoc)