Documentation Comment Specification for the Standard Doclet

This document specifies the form of documentation comments recognized by the standard doclet for the javadoc tool, used to generate HTML API documentation.

In the context of the javadoc tool, the interpretation of the content of a documentation comment is up to doclet that is used to process the comment. Other doclets may accept the same syntax as the standard doclet, or they may support an alternate syntax. However, due to support in many tools, the syntax supported by the standard doclet has become a de facto standard.

General Syntax

Documentation comments are recognized only when placed immediately before module, package, class, interface, constructor, method, or field declarations. Documentation comments placed in the body of a method are ignored. Only one documentation comment per declaration statement is recognized.

For historical reasons, the documentation comment for a package may instead be provided in a file called package.html in a source directory for the package. In this case, the documentation comment is the content of the <body> tag, and all references to Java types (for example, in @see tags) must be fully qualified. The standard doclet alse allows additional documentation to be provided in files such as overview.html. The rules for such content are the same as for package.html.

The overall form of a documentation comment is an initial (main) description, followed by a series of block tags that provide additional information about the declaration to which the comment applies. The first sentence of the initial description should be a summary sentence that contains a concise but complete description of the declared entity. Descriptive text may include HTML tags and entities, and inline tags as described below.

It is possible to have a comment with only a tag section and no initial description. The description cannot continue after the tag section begins. The argument to a tag can span multiple lines. There can be any number of tags; some types of tags can be repeated while others cannot.

Leading Asterisks

When a documentation comment is read, leading asterisks (*) on each line are discarded, and blanks and tabs that precede the initial asterisks (*) are also discarded. If you omit the leading asterisk on a line, then the leading white space is no longer removed so that you can paste code examples directly into a documentation comment inside a <pre> tag with its indentation preserved. Spaces are interpreted by browsers more uniformly than tabs. Indentation is relative to the left margin (rather than the separator /** or <pre> tag).

HTML Content

HTML content is not formally checked, although some tools may provide some amount of checking to help catch common errors.

In order to be able to generate documentation that conforms to the appropriate standards, the following considerations should be taken into account when using HTML constructs in a documentation comment:

Comment Inheritance

Class and Interface Inheritance

Comment inheritance occurs in all possible cases of inheritance from classes and interfaces:

In the first two cases, the standard doclet generates the subheading "Overrides" in the documentation for the overriding method. A link to the method being overridden is included, whether or not the comment is inherited.

In the third case, when a method in a specified class implements a method in an interface, the standard doclet generates the subheading "Specified" by in the documentation for the overriding method. A link to the method being implemented is included, whether or not the comment is inherited.

Method Comment Inheritance

The standard doclet allows method comment inheritance in classes and interfaces to fill in missing text or to explicitly inherit method comments. Constructors, fields, and nested classes do not inherit documentation comments.

Note: The source file for an inherited method must be on the path specified by the -sourcepath option for the documentation comment to be available to copy. Neither the class nor its package needs to be passed in on the command line.

Fill in Missing Text

When a main description, or @return, @param, or @throws tag is missing from a method comment, the information is copied from the method it overrides or implements (if any).

When an @param tag for a particular parameter is missing, the comment for that parameter is copied from the method further up the inheritance hierarchy. When an @throws tag for a particular exception is missing, the @throws tag is copied only when that exception is declared.

Explicit Inheritance

Insert the {@inheritDoc} inline tag in a method main description or @return, @param, or @throws tag comment. The corresponding inherited main description or tag comment is copied into that spot.

Method Comments Algorithm

If a method does not have a documentation comment, or has an {@inheritDoc} tag, then the standard doclet uses the following algorithm to search for an applicable comment. The algorithm is designed to find the most specific applicable documentation comment, and to give preference to interfaces over superclasses:

  1. Look in each directly implemented (or extended) interface in the order they appear following the word implements (or extends) in the method declaration. Use the first documentation comment found for this method.
  2. If Step 1 failed to find a documentation comment, then recursively apply this entire algorithm to each directly implemented (or extended) interface in the same order they were examined in Step 1.
  3. When Step 2 fails to find a documentation comment and this is a class other than the Object class, but not an interface:
    1. If the superclass has a documentation comment for this method, then use it.
    2. If Step 3a failed to find a documentation comment, then recursively apply this entire algorithm to the superclass.

Standard Tags

The following sections describe the standard block and inline tags supported by the standard doclet.

Note: The standard doclet also supports user-defined tags conforming to the same general syntactic rules.

Block Tags

A block tag must appear at the beginning of a line, ignoring leading asterisks, white space, and the initial comment delimiter (/**). This means you can use the @ character elsewhere in the text and it will not be interpreted as the start of a tag. If you want to start a line with the @ character and not have it be interpreted, then use the HTML entity &#064;. Each block tag has associated text, which includes any text following the tag up to, but not including, either the next block tag, or the end of the documentation comment. This associated text can span multiple lines.

@author

Adds an "Author" entry with the specified name text to the generated documents when the -author option is used. A documentation comment can contain multiple @author tags. You can specify one name per @author tag or multiple names per tag. In the former case, the standard doclet inserts a comma (,) and a space between names. In the latter case, the entire text is copied to the generated document without being parsed. Therefore, you can use multiple names per line if you want a localized name separator other than a comma.

Introduced in JDK 1.0.

@deprecated

This tag is used in conjunction with the @Deprecated annotation to indicate that this API should no longer be used (even though it may continue to work). The standard doclet moves deprecated text ahead of the main description, placing it in italics and preceding it with a bold warning.

The first sentence of deprecated text should tell the user when the API was deprecated and what to use as a replacement. The standard doclet copies the first sentence to the summary section and index. Subsequent sentences can also explain why it was deprecated. You should include an {@link} tag that points to the replacement API.

Introduced in JDK 1.0.

@exception

This tag is equivalent to the @throws tag, which is now the recommended form.

Introduced in JDK 1.0.

@hidden

Hides a program element from the generated API documentation. This tag may be used when it is not otherwise possible to design the API in a way that such items do not appear at all.

Introduced in JDK 9.

@param

Adds a parameter with the specified parameter name followed by the specified description to the "Parameters" section. The description may continue onto multiple lines. This tag is valid only in a documentation comment for a method, constructor, or class. The parameter name can be the name of a parameter in a method or constructor, or the name of a type parameter of a class, method, or constructor. Use angle brackets (< >) around such a parameter name to indicate the use of a type parameter.

Example of a type parameter of a class:

/**
 * @param <E> Type of element stored in a list
 */
public interface List<E> extends Collection<E> { ... }

Example of parameters, including type parameters, of a method:

/**
 * @param string  the string to be converted
 * @param type    the type to convert the string to
 * @param <T>     the type of the element
 * @param <V>     the value of the element
 */
<T, V extends T> V convert(String string, Class<T> type) { ... }

Introduced in JDK 1.0.

@provides

This tag may only appear in the documentation comment for a module declaration, and serves to document an implementation of a service provided by the module. The description may be used to specify how to obtain an instance of this service provider, and any important characteristics of the provider.

Introduced in JDK 9.

@return

Adds a "Returns" section with the description text. This text should describe the return type and permissible range of values. This tag is valid only in a documentation comment for a method.

Introduced in JDK 1.0.

@see

Adds a "See Also" heading with a link or text entry that points to a reference. A documentation comment can contain any number of @see tags, which are all grouped under the same heading. The @see tag has three variations. The form to reference other program elements is the most common. This tag is valid in all documentation comments. For inserting an inline link within a sentence to a package, class, or member, see {@link}.

Adds a text entry for string. No link is generated. The string may be a reference to information which is not available by URL. The standard doclet distinguishes this from the other cases by searching for a double quotation mark (") as the first character.

Adds a link as defined by the url. The URL may be a relative or absolute URL. The standard doclet distinguishes this from other cases by searching for a less-than symbol (<) as the first character.

Adds a link with a visible text label that points to the documentation for the specified name that is referenced. The label is optional; if it is omitted, then the program element name appears instead as visible text, suitably shortened. Use the -noqualifier option to globally remove the package name from this visible text. Use the label when you want the visible text to be different from the auto-generated visible text.

package.class#member is any valid program element name that is referenced, such as a package, class, interface, constructor, method or field name. Parts of the name can be omitted as appropriate. The class represents any top-level or nested class or interface. The member represents any constructor, method, or field (not a nested class or interface). If this name is in the documented classes, then the standard doclet creates a link to it.

To create links to external referenced classes, use the -link option. External referenced classes are classes that are not passed into the javadoc tool on the command line. Links in the generated documentation to external referenced classes are called external references or external links. For example, if you run the standard doclet on only the java.awt package, then any class in java.lang, such as Object, is an external referenced class. Use the -link and -linkoffline options to link to external referenced classes. The source comments of external referenced classes are not available to the javadoc command run.

Use either of the other two @see tag forms to refer to the documentation of a name that does not belong to a referenced class.

label is optional text that is visible as the link label. The label can contain white space. If label is omitted, then package.class.member appears, suitably shortened relative to the current class and package.

Introduced in JDK 1.0.

@serial

Used in the documentation comment for a default serializable field. See Documenting Serializable Fields and Data for a Class.

See also Oracle's Criteria for Including Classes in the Serialized Form Specification.

An optional field description should explain the meaning of the field and list the acceptable values. When needed, the description can span multiple lines. The standard doclet adds this information to the serialized form page.

If a serializable field was added to a class after the class was made serializable, then a statement should be added to its main description to identify at which version it was added.

The include and exclude arguments identify whether a class or package should be included or excluded from the serialized form page. They work as follows:

For example, the javax.swing package is marked with the @serial exclude tag in package-info.java. The public class java.security.BasicPermission is marked with the @serial exclude tag. The package-private class java.util.PropertyPermissionCollection is marked with the @serial include tag.

The @serial tag at the class level overrides the @serial tag at the package level.

Introduced in JDK 1.2.

@serialData

Uses the data description value to document the types and order of data in the serialized form. This data includes the optional data written by the writeObject method and all data (including base classes) written by the Externalizable.writeExternal method.

The @serialData tag can be used in the documentation comment for the readObject, writeObject, readExternal, writeExternal, readResolve, and writeReplace methods.

Introduced in JDK 1.2.

@serialField

Documents an ObjectStreamField component of the serialPersistentFields member of a Serializable class. Use one @serialField tag for each ObjectStreamField component.

Introduced in JDK 1.2.

@since

Adds a "Since" heading with the specified since-text value to the generated documentation. The text has no special internal structure. This tag is valid in any documentation comment: overview, module, package, class, interface, constructor, method, or field. This tag means that this change or feature has existed since the software release specified by the since-text value, for example: @since 1.5.

For Java platform source code, the @since tag indicates the version of the Java platform API specification, which is not necessarily when the source code was added to the reference implementation. Multiple @since tags are allowed and are treated like multiple @author tags. You could use multiple tags when the program element is used by more than one API.

Introduced in JDK 1.1.

@throws

Behaves the same as the @exception tag.

The @throws tag adds a "Throws" subheading to the generated documentation, with the class-name and description text. The class name is the name of the exception that might be thrown by the method. This tag is valid only in the documentation comment for a method or constructor. If the class name is not fully qualified, then the standard doclet uses the search order to look up this class. Multiple @throws tags can be used in a specified documentation comment for the same or different exceptions.

To ensure that all checked exceptions are documented, when an @throws tag does not exist for an exception in the throws clause, the standard doclet adds that exception to the generated output (with no description) as though it were documented with the @throws tag.

The @throws documentation is copied from an overridden method to a subclass only when the exception is explicitly declared in the overridden method. The same is true for copying from an interface method to an implementing method. You can use the {@inheritDoc} tag to force the @throws tag to inherit documentation.

Introduced in JDK 1.2.

@uses

This tag may only appear in the documentation comment for a module declaration, and serves to document that a service may be used by the module. The description may be used to specify the characteristics of the service that may be required, and what the module will do if no provider for the service is available.

Introduced in JDK 9.

@version

Adds a "Version" subheading with the specified version-text value to the generated documents when the -version option is used. This tag is intended to hold the current release number of the software that this code is part of, as opposed to the @since tag, which holds the release number where this code was introduced. The version-text value has no special internal structure.

A documentation comment can contain multiple @version tags. When it makes sense, you can specify one release number per @version tag or multiple release numbers per tag. In the former case, the standard doclet inserts a comma (,) and a space between the names. In the latter case, the entire text is copied to the generated document without being parsed. Therefore, you can use multiple names per line when you want a localized separator other than a comma.

Introduced in JDK 1.0.

Inline Tags

Inline tags are enclosed within braces ({ }) and may generally appear wherever descriptive text and HTML is permitted.

{@code}

Equivalent to <code>{@literal text }</code>.

Displays text in code font without interpreting the text as HTML markup or nested Javadoc tags. This enables you to use regular angle brackets (< and >) instead of the HTML entities (&lt; and &gt;) in documentation comments, such as in parameter types (<Object>), inequalities (3 < 4), or arrows (->). For example, the documentation comment text {@code A<B>C} displayed in the generated HTML page unchanged as A<B>C. This means that the <B> is not interpreted as bold and is in code font. If you want the same functionality without the code font, then use the {@literal} tag.

Introduced in JDK 1.5.

{@docRoot}

Represents the relative path to the generated document's (destination) root directory from any generated page. This tag is useful when you want to include a file, such as a copyright page or company logo, that you want to reference from all generated pages. Linking to the copyright page from the bottom of each page is common.

This {@docRoot} tag can be used both on the command line and in a documentation comment. This tag is valid in all documentation comments: overview, module, package, class, interface, constructor, method and field, including the text portion of any tag (such as the @return, @param and @deprecated tags).

For example, on the command line, where the header, footer, or bottom are defined:

javadoc -bottom '<a href="{@docRoot}/copyright.html">Copyright</a>'.

When you use the {@docRoot} tag this way in a make file, some makefile programs require a special way to escape for the brace {} characters. For example, the Inprise MAKE version 5.2 running on Windows requires double braces: {{@docRoot}}. It also requires double (rather than single) quotation marks to enclose arguments to options such as the -bottom option (with the quotation marks around the href argument omitted).

For example, in a documentation comment:

/**
 * See the <a href="{@docRoot}/copyright.html">Copyright</a>.
 */

This tag is needed because the generated documents are in hierarchical directories, as deep as the number of subpackages. The expression <a href="{@docRoot}/copyright.html"> resolves to <a href="../../copyright.html"> for java/lang/Object.java and <a href="../../../copyright.html"> for java/lang/ref/Reference.java.

Introduced in JDK 1.3.

{@index}

Declares that a word or phrase, together with an optional short description, should appear in the index files generated by the standard doclet. The index entry will be linked to the word or phrase that will appear at this point in the generated documentation. The description may be used when the word or phrase to be indexed is not clear by itself, such as for an acronym.

Introduced in JDK 9.

{@inheritDoc}

Inherits (copies) documentation from the nearest inheritable class or implementable interface into the current documentation comment at this tag's location. This enables you to write more general comments higher up the inheritance tree and to write around the copied text.

This tag is valid only in these places in a documentation comment:

See Method Comment Inheritance for a description of how comments are found in the inheritance hierarchy. Note that if this tag is missing, then the comment is or is not automatically inherited according to rules described in that section.

Introduced in JDK 1.4.

Inserts an inline link with a visible text label that points to the documentation for the specified package, class, or member name of a referenced class. This tag is valid in all documentation comments: overview, module, package, class, interface, constructor, method and field, including the text portion of any tag, such as the @return, @param and @deprecated tags.

This tag is similar to the @see tag. Both tags require the same references and accept the same syntax for package.class#member and label. The main difference is that the {@link} tag generates an inline link rather than placing the link in the "See Also" section. The {@link} tag begins and ends with braces to separate it from the rest of the inline text. If you need to use the right brace (}) inside the label, then use the HTML entity notation &#125;.

There is no limit to the number of {@link} tags allowed in a sentence.

For example, here is a comment that refers to the getComponentAt(int, int) method:

Use the {@link #getComponentAt(int, int) getComponentAt} method.

From this code, the standard doclet generates the following HTML (assuming it refers to another class in the same package):

Use the <a href="Component.html#getComponentAt(int, int)">getComponentAt</a> method.

The previous line appears on the web page as:

Use the getComponentAt method.

Introduced in JDK 1.2.

{@linkplain}

Behaves the same as the {@link} tag, except the link label is displayed in plain text rather than code font. Useful when the label is plain text. For example, Refer to {@linkplain add() the overridden method}. displays as: Refer to the overridden method.

Introduced in JDK 1.4.

{@literal}

Displays text without interpreting the text as HTML markup or nested Javadoc tags. This enables you to use angle brackets (< and >) instead of the HTML entities (&lt; and &gt;) in documentation comments, such as in parameter types (<Object>), inequalities (3 < 4), or arrows (->). For example, the documentation comment text {@literal A<B>C} displays unchanged in the generated HTML page in your browser, as A<B>C. The <B> is not interpreted as bold (and it is not in code font). If you want the same functionality with the text in code font, then use the {@code} tag.

Introduced in JDK 1.5.

{@summary}

Identify the summary of an API description, as an alternative to the default policy to identify and use the first sentence of the API description. The tag only has significance when used at the beginning of a description. In all cases, the tag is rendered by simply rendering its content.

Introduced in JDK 10.

{@systemProperty}

Identify property-name as the name of a system property. The name should be a "dotted identifier". In particular, it must not contain white space characters, or characters such as }. No other content is permitted in the tag; the possibility of additional content is reserved for future use. The tag can be used in the documentation comments for modules, packages, types, fields and executable members.

Introduced in JDK 12.

{@value}

Displays constant values. When the {@value} tag is used without an argument in the documentation comment of a static field, it displays the value of that constant:

/**
 * The value of this constant is {@value}.
 */
public static final String SCRIPT_START = "<script>"

When used with the argument package.class#field in any documentation comment, the {@value} tag displays the value of the specified constant:

/**
 * Evaluates the script starting with {@value #SCRIPT_START}.
 */
public String evalScript(String script) {}

The argument package.class#field takes a form similar to that of the @see tag argument, except that the member must be a static field.

Introduced in JDK 1.4.

Where Tags Can Be Used

The following table summarizes which tags can be used in which contexts.

Tag Overview Module Package Type Constructor Method Field
@author
{@code}
@deprecated
{@docRoot}
@exception
@hidden
{@index}
{@inheritDoc}
{@link}
{@linkplain}
{@literal}
@param
@provides
@return
@see
@serial
@serialData *
@serialField *
@since
{@summary}
{@systemProperty}
@throws
@uses
{@value}
@version

Notes: