Java Documentation Comments

Introduction

Document tags that begin with an @ are called stand-alone tags.

They must be used on their own line.

Tags that begin with a brace, such as {@code}, are called in-line tags, and they can be used within a larger description.

You may also use other, standard HTML tags in a documentation comment.

The javadoc Tags

The javadoc utility recognizes the following tags:

TagMeaning
@authorIdentifies the author.
{@code}Displays information as-is, without processing HTML styles, in code font.
@deprecated Specifies that a program element is deprecated.
{@docRoot} Specifies the path to the root directory of the current documentation.
@exception Identifies an exception thrown by a method or constructor.
{@inheritDoc}Inherits a comment from the immediate superclass.
{@link}Inserts an in-line link to another topic.
{@linkplain} Inserts an in-line link to another topic, but the link is displayed in a plain-text font.
{@literal} Displays information as-is, without processing HTML styles.
@param Documents a parameter.
@returnDocuments a method's return value.
@seeSpecifies a link to another topic.
@serial Documents a default serializable field.
@serialDataDocuments the data written by the writeObject() or writeExternal() methods.
@serialFieldDocuments an ObjectStreamField component.
@sinceStates the release when a specific change was introduced.
@throws Same as @exception.
{@value}Displays the value of a constant, which must be a static field.
@version Specifies the version of a class.

@author

The @author tag documents the author of a class or interface.

It has the following syntax:

@author description 

Here, description is the name of the author.

You will need to specify the -author option when executing javadoc in order for the @author field to be included in the HTML documentation.

{@code}

The {@code} tag can embed a snippet of code into a comment.

That text is displayed as-is in code font, without any further processing.

It has the following syntax:

{@code code-snippet} 

@deprecated

The @deprecated tag marks that a program element is deprecated.

It is recommended that you include @see or {@link} tags to inform the programmer about available alternatives.

The syntax is the following:

@deprecated description 

Here, description is the message that describes the deprecation.

The @deprecated tag can be used in documentation for fields, methods, constructors, classes, and interfaces.

{@docRoot}

{@docRoot} sets the path to the root directory of the current documentation.

@exception

The @exception tag marks an exception to a method.

It has the following syntax:

@exception exception-name explanation 

Here, the fully qualified name of the exception is marked by exception-name.

explanation is a string that describes how the exception can occur.

The @exception tag can only be used in documentation for a method or constructor.

{@inheritDoc}

{@inheritDoc} tag inherits a comment from the immediate superclass.

{@link}

The {@link} tag sets an in-line link to additional information.

It has the following syntax:

{@link pkg.class#member text} 

Here, pkg.class#member specifies the name of a class or method to which a link is added, and text is the string that is displayed.

{@linkplain}

Inserts an in-line link to another topic.

The link is displayed in plain-text font. Otherwise, it is similar to {@link}.

{@literal}

The {@literal} tag can embed text into a comment.

That text is then displayed as-is, without any further processing.

It has the following syntax:

{@literal description}

Here, description is the text that is embedded.

@param

The @param tag documents a parameter.

It has the following syntax:

@param parameter-name explanation 

Here, parameter-name specifies the name of a parameter.

The meaning of that parameter is described by explanation.

The @param tag can be used only in documentation for a method or constructor, or a generic class or interface.

@return

The @return tag describes the return value of a method.

It has the following syntax:

@return explanation 

Here, explanation describes the type and meaning of the value returned by a method.

The @return tag can be used only in documentation for a method.

@see

The @see tag provides a reference to additional information.

Two commonly used forms are shown here:

@see anchor  
@see pkg.class#member text 

anchor is a link to an absolute or relative URL.

pkg.class#member sets the name of the item, and text is the text displayed for that item.

@serial

The @serial tag defines the comment for a default serializable field.

It has the following syntax:

@serial description 

Here, description is the comment for that field.

@serialData

The @serialData tag documents the data written by the writeObject() and writeExternal() methods.

It has the following syntax:

@serialData description 

Here, description is the comment for that data.

@serialField

For a class that implements Serializable, the @serialField tag provides comments for an ObjectStreamField component.

It has the following syntax:

@serialField name type description 

Here, name is the name of the field, type is its type, and description is the comment for that field.

@since

The @since tag states that an element was introduced in a specific release.

It has the following syntax:

@since release 

Here, release is a string that designates the release or version in which this feature became available.

@throws

The @throws tag has the same meaning as the @exception tag.

{@value}

{@value} has two forms.

The first displays the value of the constant.

It has this form:

{@value} 

The second form displays the value of a specified static field.

It has this form:

{@value pkg.class#field} 

Here, pkg.class#field specifies the name of the static field.

@version

The @version tag specifies the version of a class or interface.

It has the following syntax:

@version info 

Here, info is a string that contains version information, typically a version number, such as 1.0.

To include the version number in the HTML documentation, specify the -version option in command line when executing javadoc.




PreviousNext

Related