Java - Documentation Comments
Java - Documentation Comments
1 /* text */
2
//text
3
/** 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.
This chapter is all about explaining Javadoc. We will see how we can make use of Javadoc to
generate useful documentation for Java code.
What is Javadoc?
Javadoc is a tool which 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 which preceeds // is Java single-line comment.
Example
/**
* @version 1.0
* @since 2014-03-31
*/
https://www.tutorialspoint.com/java/java_documentation.htm 1/7
15/04/2022, 16:17 Java - Documentation Comments
System.out.println("Hello World!");
You can include required HTML tags inside the description part. For instance, the following
example makes use of <h1>....</h1> for heading and <p> has been used for creating paragraph
break −
Example
/**
* <h1>Hello, World!</h1>
* <p>
* @version 1.0
* @since 2014-03-31
*/
System.out.println("Hello World!");
https://www.tutorialspoint.com/java/java_documentation.htm 2/7
15/04/2022, 16:17 Java - Documentation Comments
{@link} Inserts an in-line link with the visible text label that
{@link
points to the documentation for the specified
package.class#member
package, class, or member name of a referenced
label}
class.
@return Adds a "Returns" section with the description text. @return description
@serial Used in the doc comment for a default serializable @serial field-
field. description | include |
exclude
https://www.tutorialspoint.com/java/java_documentation.htm 3/7
15/04/2022, 16:17 Java - Documentation Comments
description
@throws The @throws and @exception tags are synonyms. @throws class-name
description
Example
Following program uses few of the important tags available for documentation comments. You
can make use of other tags based on your requirements.
The documentation about the AddNum class will be produced in HTML file AddNum.html but at
the same time a master file with a name index.html will also be created.
import java.io.*;
/**
* <p>
* @version 1.0
* @since 2014-03-31
*/
/**
*/
https://www.tutorialspoint.com/java/java_documentation.htm 4/7
15/04/2022, 16:17 Java - Documentation Comments
/**
* @return Nothing.
* @see IOException
*/
Now, process the above AddNum.java file using javadoc utility as follows −
$ javadoc AddNum.java
Generating /AddNum.html...
Generating /package-tree.html...
Generating /constant-values.html...
Generating /overview-tree.html...
Generating /index-all.html...
Generating /deprecated-list.html...
Generating /allclasses-noframe.html...
Generating /index.html...
Generating /help-doc.html...
1 warning
https://www.tutorialspoint.com/java/java_documentation.htm 5/7
15/04/2022, 16:17 Java - Documentation Comments
You can check all the generated documentation here − AddNum . If you are using JDK 1.7
then javadoc does not generate a great stylesheet.css, so we suggest to download and use
standard stylesheet from https://docs.oracle.com/javase/7/docs/api/stylesheet.css
16 Lectures 2 hours
Malhar Lathkar
More Detail
Video
19 Lectures 5 hours
Malhar Lathkar
More Detail
Video
More Detail
https://www.tutorialspoint.com/java/java_documentation.htm 6/7
15/04/2022, 16:17 Java - Documentation Comments
Video
More Detail
Video
Monica Mittal
More Detail
Video
76 Lectures 7 hours
Arnab Chakraborty
More Detail
https://www.tutorialspoint.com/java/java_documentation.htm 7/7