javadoc - The Java API Documentation Generator

Generates HTML pages of API documentation from Java source files.



javadoc [ options ] [ packagenames ] [ sourcefiles ] [ @files ]
Arguments may be in any order.
Command-line options, as specified in this document. To see a typical use of javadoc options, see Real-World Example.
A series of names of packages, separated by spaces, such as java.lang java.lang.reflect java.awt. You must separately specify each package you want to document. Javadoc does not recursively traverse subpackages. Wildcards such as asterisks (*) are not allowed. See Example - Documenting One or More Packages
A series of source file names, separated by spaces, which can include paths and wildcards such as asterisk (*). For example: /home/src/java/awt/Graphics*.java See Example - Documenting One or More Classes. You can also mix packagenames and sourcefiles, as in Example - Documenting Both Packages and Classes
One or more files that contain packagenames and sourcefiles in any order.


Javadoc parses the declarations and documentation comments in a set of Java source files and produces a corresponding set of HTML pages describing (by default) the public and protected classes, inner classes, interfaces, constructors, methods, and fields.

You can run Javadoc on entire packages, individual source files, or both. In the first case, you pass in as an argument to javadoc a series of package names. In the second case you pass in a series of source (.java) filenames. Examples are given at the end of this document.

As implemented, Javadoc requires and relies on the java compiler to do its job. Javadoc calls part of javac to compile the declarations, ignoring the member implementation. It builds a rich internal representation of the classes, including the class hierarchy, and "use" relationships, then generates the HTML from that. Javadoc also picks up user-supplied documentation from documentation comments in the source code.

In fact, Javadoc will run on .java source files that are pure stub files with no method bodies. This means you can write documentation comments and run Javadoc in the earliest stages of design while creating the API, before writing any code.

Relying on the compiler ensures that the HTML output corresponds exactly with the actual implementation, which may rely on implicit, rather than explicit, source code. For example, Javadoc documents default constructors (section 8.6.7 of Java Language Specification) that are present in the .class files but not in the source code.

When Javadoc builds its internal structure for the documentation, it loads all referenced classes. Because of this, Javadoc must be able to find all referenced classes, whether bootstrap classes, extensions, or user classes. For more about this, see How Classes Are Found. Generally speaking, classes you create must either be loaded as an extension or in Javadoc's class path.

Javadoc Doclets

You can customize the content and format of Javadoc's output by using doclets. Javadoc has a default "built-in" doclet, called the standard doclet, that generates HTML-formatted API documentation. You can modify or subclass the standard doclet, or write your own doclet to generate HTML, XML, MIF, RTF or whatever output format you'd like. Information about doclets and their use is at the following locations: When a custom doclet is not specified with the -doclet command line option, Javadoc will use the default standard doclet. The javadoc tool has several command line options that are available regardless of which doclet is being used. The standard doclet adds a supplementary set of command line options. Both sets of options are described below in the options section.

Related Documentation


A few terms have specific meanings within the context of Javadoc:
generated document
The document generated by the javadoc tool from the doc comments in Java source code. The default generated document is in HTML and is created by the standard doclet.

A name in the Java Language, namely the name of a package, class, interface, field, constructor or method. A name can be fully-qualified, such as java.lang.String.equals(java.lang.Object), or partially-qualified, such as equals(Object).

documented classes
The classes and interfaces for which full documentation is generated during a javadoc run. To be documented, the source files must be available, and either their source filenames or package names must be passed into the javadoc command. We also refer to these as the classes included in the javadoc run, or the included classes.

referenced classes
The classes and interfaces that are explicitly referred to in the definition (implementation) of the documented classes and interfaces. Examples of references include return type, parameter type, cast type, extended class, implemented interface, imported classes, and so forth. Classes referred to in doc comments (such as @see tags) do not qualify as referenced classes. When Javadoc is run, it loads into memory all of the referenced classes in javadoc's bootclasspath and classpath. (Javadoc prints a "Class not found" warning for referenced classes not found.) Javadoc can derive enough information from the the .class files to determine their existence and the fully-qualified names of its members.

external referenced classes
The referenced classes whose documentation is not being generated during a javadoc run. In other words, these classes are external to that javadoc run. Links for names in the documentation to those classes are said to be external references or external links. For example, if you run javadoc on only the java.awt package, then any class in java.lang, such as Object, is an external referenced class. External referenced classes can be linked to using the -link option.


Javadoc will generate output originating from four different types of "source" files: Java language source files (.java), package comment files, overview comment files, and miscellaneous unprocessed files. The following section describes the latter three types.

Package Comment Files

Each package can have its own documentation comment, kept in its own "source" file, that Javadoc will merge into the package summary page that it generates. You typically include in this comment any documentation that applies to the entire package.

To create a package comment file, you must name it package.html and place it in the package directory in the source tree along with the .java files. Javadoc will automatically look for this filename in this location. Notice that the filename is identical for all packages.

The content of the package comment file is one big documentation comment, written in HTML, like all other comments, with one exception: The documentation comment should not include the comment separators /** and */ or leading asterisks. When writing the comment, you should make the first sentence a summary about the package, and not put a title or any other text between <body> and the first sentence. You can include package tags; as with any documentation comment, all tags except {@link} must appear after the description. If you add a @see tag, it must have a fully-qualified name.

When Javadoc runs, it will automatically look for this file; if found, Javadoc does the following:

Overview Comment File

Each application or set of packages that you are documenting can have its own overview documentation comment, kept in its own "source" file, that Javadoc will merge into the overview page that it generates. You typically include in this comment any documentation that applies to the entire application or set of packages.

To create an overview comment file, you can name the file anything you want, typically overview.html and place it anywhere, typically at the top level of the source tree. Notice you can have multiple overview comment files for the same set of source files, in case you want to run javadoc multiple times on different sets of packages. For example, if the source files for the java.applet package are contained in C:\user\src\java\applet directory, you could create an overview comment file at C:\user\src\overview.html.

The content of the overview comment file is one big documentation comment, written in HTML, like the package comment file described previously. See that description for details. To re-iterate, when writing the comment, you should make the first sentence a summary about the application or set of packages, and not put a title or any other text between <body> and the first sentence. You can include overview tags; as with any documentation comment, all tags except {@link} must appear after the description. If you add a @see tag, it must have a fully-qualified name.

When you run Javadoc, you specify the overview comment file name with the -overview option. The file is then processed similar to that of a package comment file.

Miscellaneous Unprocessed Files

You can also include in your source any miscellaneous files that you want Javadoc to copy to the destination directory. These typically includes graphic files, example Java source (.java) and class (.class) files, and self-standing HTML files whose content would overwhelm the documentation comment of a normal Java source file.

To include unprocessed files, put them in a directory called doc-files which can be a subdirectory of any package directory. You can have one such subdirectory for each package. For example, if you want to include the image of a button button.gif in the java.awt.Button class documentation, you place that file in the /home/user/src/java/awt/doc-files/ directory. All links to these unprocessed files must be hard-coded, because Javadoc does not look at the files -- it simply copies the directory and all its contents to the destination. For example, the link in the doc comment might look like:

     * This button looks like this: 
     * <img src="doc-files/Button.gif">


By default, javadoc uses a standard doclet that generates HTML-formatted documentation. This doclet generates the following kinds of files (where each HTML "page" corresponds to a separate file). Note that javadoc generates files with two types of names: those named after classes/interfaces, and those that are not (such as package-summary.html). Files in the latter group contain hyphens (to prevent filename conflicts with those in the former group).

Basic Content Pages

Cross-Reference Pages

Support Files

HTML Frames

Javadoc will generate either two or three HTML frames, as shown in the figure below. When you pass source files (*.java) or a single package name as arguments into the javadoc command, it will create only one frame (C) in the left-hand column -- the list of classes. When you pass into javadoc two or more package names, it creates a third frame (P) listing all packages, as well as an overview page (Detail). You can bypass frames by clicking on the "No Frames" link or entering at overview-summary.html.

If you are unfamiliar with HTML frames, you should be aware that frames can have focus for printing and scrolling. To give a frame focus, click on it. Then on many browsers the arrow keys and page keys will scroll that frame, and the print menu command will print it.

              ------------                  ------------
              |C| Detail |                  |P| Detail |
              | |        |                  | |        |
              | |        |                  |-|        |
              | |        |                  |C|        |
              | |        |                  | |        |
              | |        |                  | |        |
              ------------                  ------------
             javadoc *.java           javadoc java.lang java.awt
Load one of the following two files as the starting page depending on whether you want HTML frames or not: Generated File Structure

The generated class and interface files are organized in the same directory hierarchy that Java source files and class files are organized. This structure is one directory per subpackage.

For example, the document generated for the class java.applet.Applet class would be located at java\applet\Applet.html. The file structure for the java.applet package follows, given that the destination directory is named apidocs. All files that contain the word "frame" appear in the upper-left or lower-left frames, as noted. All other HTML files appear in the right-hand frame.

NOTE - Directories are shown in bold. The asterisks (*) indicate the files and directories that are omitted when the arguments to javadoc are source filenames (*.java) rather than package names. Also when arguments are source filenames, package-list is created but is empty. The doc-files directory will not appear in the destination unless it exists in the source tree.

apidocs                             Top directory
   index.html                       Initial page that sets up HTML frames
 * overview-summary.html            Lists all packages with first sentence summaries
   overview-tree.html               Lists class hierarchy for all packages
   deprecated-list.html             Lists deprecated API for all packages
   serialized-form.html             Lists serialized form for all packages
 * overview-frame.html              Lists all packages, used in upper-left frame
   allclasses-frame.html            Lists all classes for all packages, used in lower-left frame
   help-doc.html                    Lists user help for how these pages are organized
   index-all.html                   Default index created without -splitindex option
   index-files                      Directory created with -splitindex option
       index-<number>.html          Index files created with -splitindex option
   package-list                     Lists package names, used only for resolving external refs
   stylesheet.css                   HTML style sheet for defining fonts, colors and positions
   java                             Subpackage directory
       applet                       Subpackage directory
            Applet.html             Page for Applet class
            AppletContext.html      Page for AppletContext interface
            AppletStub.html         Page for AppletStub interface
            AudioClip.html          Page for AudioClip interface
          * package-summary.html    Lists classes with first sentence summaries for this package
          * package-frame.html      Lists classes in this package, used in lower left-hand frame
          * package-tree.html       Lists class hierarchy for this package
            package-use             Lists where this package is used
            doc-files               Directory holding image and example files
            class-use               Directory holding pages API is used
                Applet.html         Page for uses of Applet class
                AppletContext.html  Page for uses of AppletContext interface
                AppletStub.html     Page for uses of AppletStub interface
                AudioClip.html      Page for uses of AudioClip interface


Commenting the Source Code

You can include documentation comments in the source code, ahead of declarations for any entity (classes, interfaces, methods, constructors, or fields). These are also known as Javadoc comments, and the text must be written in HTML, in that they should use HTML entities and can use HTML tags. You can use whichever version of HTML your browser supports; we have written the standard doclet to generate HTML 3.2-compliant code elsewhere (outside of the documentation comments) with the inclusion of cascading style sheets and frames. (We preface each generated file with "HTML 4.0" because of the frame sets.)

For example, entities for the less-than (<) and greater-than (>) symbols should be written &lt; and &gt;. Likewise, the ampersand (&) should be written &amp;. The bold HTML tag <b> is shown in the following example.

Here is a doc comment:

 * This is a <b>doc</b> comment.
 * @see java.lang.Object

A doc comment consists of the characters between the characters /** that begin the comment and the characters */ that end it. The text is divided into one or more lines. When javadoc parses a doc comment, leading asterisk (*) characters on each line are discarded; blanks and tabs preceding the initial asterisk (*) characters are also discarded. If you omit the leading asterisk on a line, all leading white space is removed. (To a degree, leading asterisks can be omitted. One place omitting the leading asterisks causes a problem is when formatting indents over multiple lines with the <pre> tag, such as with sample code. Without leading asterisks, the indents are lost in the generated documents, since the leading white space is removed.)

The first sentence of each doc comment should be a summary sentence, containing a concise but complete description of the declared entity. This sentence ends at the first period that is followed by a blank, tab, or line terminator, or at the first tag. Javadoc copies this first sentence to the member summary at the top of the HTML page.

Documentation comments are only recognized when placed immediately before class, interface, constructor, method, or field declarations. Only one documentation comment per declaration is recognized by the Javadoc tool.

When you embed HTML tags within a doc comment, you should not use HTML heading tags such as <H1> and <H2>, because Javadoc creates an entire structured document and these structural tags interfere with the formatting of the generated document.

The first line of a documentation comment that begins with the character @ ends the description and starts the section of tagged paragraphs. The tag @see in the above example is such a tagged paragraph.

For the specification on documentation comments, see Chapter 18, Documentation Comments, in the Java Language Specification, by James Gosling, Bill Joy, and Guy Steele.


Javadoc parses special tags when they are embedded within a Java doc comment. These doc tags enable you to autogenerate a complete, well-formatted API from your source code. The tags start with an "at" sign (@) and are case-sensitive -- they must be typed with the uppercase and lowercase letters as shown. A tag must start at the beginning of a line (after any leading spaces and an optional asterisk) or it is treated as normal text. By convention, group tags with the same name together. For example, put all @see tags together.

For information about tags we might introduce in future releases, see Proposed Tags.

The current tags are:

Tag Introduced in JDK
@author 1.0
@deprecated 1.0
@exception 1.0
{@link} 1.2
@param 1.0
@return 1.0
@see 1.0
@serial 1.2
@serialData 1.2
@serialField 1.2
@since 1.1
@throws 1.2
@version 1.0
@author  name-text
Adds an "Author" entry with the specified name-text to the generated docs when the -author option is used. A doc comment may contain multiple @author tags. You can specify one name per @author tag or multiple names per tag. In the former case, Javadoc inserts a comma (,) and space between names. In the latter case, the entire text is simply copied to the generated document without being parsed. Therefore, use multiple names per line if you want a localized name separator other than comma.

@deprecated  deprecated-text
Adds a comment indicating that this API should no longer be used (even though it may continue to work). Javadoc moves the deprecated-text ahead of the description, placing it in italics and preceding it with a bold warning: "Deprecated".

The first sentence of deprecated-text should at least tell the user when the API was deprecated and what to use as a replacement. Javadoc copies just the first sentence to the summary section and index. Subsequent sentences can also explain why it has been deprecated. You should include a {@link} tag (for Javadoc 1.2 or later) that points to the replacement API:

  • For Javadoc 1.2, use a {@link} tag. This creates the link in-line, where you want it. For example:
     * @deprecated  As of JDK 1.1, replaced by {@link #setBounds(int,int,int,int)}
  • For Javadoc 1.1, the standard format is to create a @see tag (which cannot be in-line) for each @deprecated tag.

For more about deprecation, see The @deprecated tag.

@exception  class-name  description
The @exception tag is a synonym for @throws.

{@link  name  label}
Inserts an in-line link that points to the specified name. This tag accepts exactly the same syntax for name and label as the @see tag, described below, but generates an in-line link rather than placing the link in the "See Also" section. This tag begins and ends with curly braces to separate it from the rest of the in-line text. If you need to use "}" inside the label, use the HTML entity notation &#125;

There is no limit to the number of {@link} tags allowed in a sentence. You can use this tag in the description part of a documentation comment or in the text portion of any tag (such as @deprecated, @return or @param).

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

Use the {@link #getComponentAt(int, int) getComponentAt} method.
From this, the standard doclet would generate 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.
Which appears on the web page as:
Use the getComponentAt method.
@param  parameter-name description
Adds a parameter to the "Parameters" section. The description may be continued on the next line.

@return  description
Adds a "Returns" section with the description text. This text should describe the return type and permissible range of values.

@see  reference
Adds a "See Also" heading with a link or text entry that points to reference. A doc comment may contain any number of @see tags, which are all grouped under the same heading. The @see tag has three variations; the third form below is the most common.

@see "string"     Note - This form is broken in JDK 1.2. It prints none of the quoted text.
Adds a text entry for string. No link is generated. The string is a book or other reference to information not available by URL. Javadoc distinguishes this from the previous cases by looking for a double-quote (") as the first character. For example:
     @see "The Java Programming Language"
This generates text such as:
See Also:
"The Java Programming Language"
@see <a href="URL#value">label</a>
Adds a link as defined by URL#value. The URL#value is a relative or absolute URL. Javadoc distinguishes this from other cases by looking for a less-than symbol (<) as the first character. For example:
     @see <a href="spec.html#section">Java Spec</a>
This generates a link such as:
See Also:
Java Spec
@see  package.class#member  label
Adds a link, with visible text label, that points to the documentation for the specified name in the Java Language. The label is optional; if omitted, the name appears instead as the visible text, embedded within <code> HTML tags. Use the label when you want the visible text to be abbreviated or different from the name.

  • package.class#member is any valid name in the Java Language -- the name of a package, class, interface, constructor, method or field -- except that you replace the dot ahead of the member name with a hash character (#). If this name is in the documented classes, Javadoc will automatically create a link to it. To create links to external referenced classes, use the -link option. Use either of the other two @see forms for referring to documentation of a name that does not belong to a referenced class. This first argument is described at greater length below under Specifying a Name.

  • label is optional text that is visible as the link's label. The label can contain whitespace. If label is omitted, then package.class.member will appear, suitably shortened relative to the current class and package -- see How a name is displayed.

  • A space is the delimiter between package.class#member and label. A space inside parentheses does not indicate the start of a label, so spaces may be used between parameters in a method.

Example - In this example, the @see tag in the Character class refers to the equals method in the String class. The tag includes both arguments: the name "String#equals(Object)" and the label "equals".

  * @see String#equals(Object) equals
The standard doclet produces HTML something like this:
<dt><b>See Also:</b>
<dd><a href="../../java/lang/String#equals(java.lang.Object)">equals</a>
Which looks something like this in a browser, where the label is the visible link text:

See Also:

Specifying a name - This package.class#member name can be either fully-qualified, such as java.lang.String#toUpperCase() or not, such as String#toUpperCase() or #toUpperCase(). If less than fully-qualified, Javadoc uses the normal Java compiler search order to find it, further described below in Search order for @see. The name can contain whitespace within parentheses, such as between method arguments.

Of course the advantage to providing shorter, "partially-qualified" names is that they are less to type and less clutter in the source code. The following table shows the different forms of the name, where Class can be a class or interface, Type can be a class, interface, array, or primitive, and method can be a method or constructor.

Typical forms for @see package.class#member
Referencing a member of the current class
@see  #field
@see  #method(Type, Type,...)
@see  #method(Type argname, Type argname,...)

Referencing another class in the current or imported packages
@see  Class#field
@see  Class#method(Type, Type,...)
@see  Class#method(Type argname, Type argname,...)
@see  Class

Referencing another package (fully qualified)
@see  package.Class#field
@see  package.Class#method(Type, Type,...)
@see  package.Class#method(Type argname, Type argname,...)
@see  package.Class
@see  package

The following notes apply to the above table:

  • The first set of forms (with no class or package) will cause Javadoc to search only through the current class's hierarchy. It will find a member of the current class or interface, one of its superclasses or superinterfaces, or one of its enclosing classes or interfaces (search steps 1-3). It will not search the rest of the current package or other packages (search steps 4-5).
  • If any method or constructor is entered as a name with no parentheses, such as getValue, and if there is no field with the same name, Javadoc will correctly create a link to it, but will print a warning message reminding you to add the parentheses and arguments. If this method is overloaded, Javadoc will link to the first method its search encounters, which is unspecified.
  • Inner classes must be specified as outer.inner, not simply inner, for all forms.
  • As stated, the hash character (#), rather than a dot (.) separates a member from its class. This enables Javadoc to resolve ambiguities, since the dot also separates classes, inner classes, packages, and subpackages. The hash character is absolutely necessary in the forms above where it is the first character. However, in other forms, Javadoc is generally lenient and will allow a dot if it does not produce an ambiguity, though it will print a warning.

Search order for @see - Javadoc will process a @see tag that appears in a source file (.java), package file (package.html) or overview file (overview.html). In the latter two files, you must fully-qualify the name you supply with @see. In a source file, you can specify a name that is fully-qualified or partially-qualified.

When Javadoc encounters a @see tag in a .java file that is not fully qualified, it searches for the specified name in the same order as the Java compiler would (except Javadoc will not detect certain namespace ambiguities, since it assumes the source code is free of these errors). This search order is formally defined in Chapter 6, "Names" of the Java Language Specification, modified by the Inner Classes Specification. Javadoc searches for that name through all related and imported classes and packages. In particular, it searches in this order:

  1. the current class or interface
  2. any enclosing classes and interfaces, searching closest first
  3. any superclasses and superinterfaces, searching closest first
  4. the current package
  5. any imported packages, classes and interfaces, searching in the order of the import statement

Javadoc continues to search recursively through steps 1-3 for each class it encounters until it finds a match. That is, after it searches through the current class and its enclosing class E, it will search through E's superclasses before E's enclosing classes. In steps 4 and 5, Javadoc does not search classes or interfaces within a package in any specified order (that order depends on the particular compiler). In step 5, Javadoc will look in java.lang, since that is automatically imported by all programs.

Javadoc won't necessarily look in subclasses, nor will it look in other packages even if their documentation is being generated in the same run. For example, if the @see tag is in java.awt.event.KeyEvent class and refers to a name in the java.awt package, javadoc will not look in that package unless that class imports it.

How a name is displayed - If label is omitted, then package.class.member will appear. In general, it will be suitably shortened relative to the current class and package. By "shortened", we mean Javadoc will display only the minimum name necessary. For example:

Method Containing @see Tag @see Tag Displays As
String.toUpperCase() @see String#toLowerCase()
(refers to member of the same class)
(omits the class name)
String.toUpperCase() @see Character#toLowerCase(char)
(refers to member of a different class)
(includes the class name)

Examples of @see
The comment to the right shows how the name would be displayed if the @see tag is in a class in another package, such as java.applet.Applet.

                                           See also: 
@see java.lang.String                   //  String                           
@see java.lang.String The String class  //  The String class                 
@see String                             //  String                           
@see String#equals(Objetc)              //  String.equals(Object)            
@see String#equals                      //  String.equals(java.lang.Object)   
@see java.lang.Object#wait(long)        //  java.lang.Object.wait(long)      
@see Character#MAX_RADIX                //  Character.MAX_RADIX              
@see <a href="spec.html">Java Spec</a>  //  Java Spec            
@see "The Java Programming Language"    //  "The Java Programming Language"         
@since  since-text
Adds a "Since" heading with the specified since-text to the generated documentation. The text has no special internal structure. This tag means that this change or feature has existed since the software release specified by the since-text. For example:
    @since JDK1.1

@serial  field-description
Used in the doc comment for a default serializable field.

An optional field-description augments the doc comment for the field. The combined description must explain the meaning of the field and list the acceptable values. If needed, the description can span multiple lines.

The @since tag should be added to each serializable field that has been added since the initial version of a Serializable class.

To get a serialized form for a private class, use the -private option. Therefore, to generate the serialized form for all public and private classes, run javadoc with this -private option.

For more information about how to use these tags, along with an example, see "Documenting Serializable Fields and Data for a Class," Section 1.6 of the Java Object Serialization Specification.

@serialField  field-name  field-type  field-description
Documents an ObjectStreamField component of a Serializable class' serialPersistentFields member. One @serialField tag should be used for each ObjectStreamField component.

@serialData  data-description
A data-description documents the sequences and types of data, specifically the optional data written by the writeObject method and all data written by the Externalizable.writeExternal method.

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

@throws  class-name  description
The @throws and @exception tags are synonyms. 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 may be thrown by the method. If this class is not fully-specified, Javadoc uses the search order to look up this class.

@version  version-text
Adds a "Version" subheading with the specified version-text to the generated docs when the -version option is used. The text has no special internal structure. A doc comment may contain at most one @version tag. Version normally refers to the version of the software (such as the JDK) that contains this class or member.


The following sections describe where the tags can be used. Note that these four tags can be used in all doc comments: @see, @link, @since, @deprecated.

Overview Documentation Tags

Overview tags are tags that can appear in the documentation comment for the overview page (which resides in the source file typically named overview.html). Like in any other documentation comments, these tags must appear after the description.

NOTE - The {@link} tag has a bug in overview documents in JDK 1.2 -- the text appears properly but has no link.

Overview Tags

Package Documentation Tags

Package tags are tags that can appear in the documentation comment for a package (which resides in the source file named package.html).

Package Tags

Class and Interface Documentation Tags

The following are tags that can appear in the documentation comment for a class or interface.

Class/Interface Tags

An example of a class comment:

 * A class representing a window on the screen.
 * For example:
 * <pre>
 *    Window win = new Window(parent);
 * </pre>
 * @author  Sami Shaio
 * @version %I%, %G%
 * @see     java.awt.BaseWindow
 * @see     java.awt.Button
class Window extends BaseWindow {

Field Documentation Tags

The following are the tags that can appear in the documentation comment for a field.

Field Tags

An example of a field comment:

     * The X-coordinate of the component.
     * @see #getLocation()
    int x = 1263732;

Constructor and Method Documentation Tags

The following are the tags that can appear in the documentation comment for a constructor or method.

Method/Constructor Tags
@throws (@exception)

An example of a method doc comment:

     * Returns the character at the specified index. An index 
     * ranges from <code>0</code> to <code>length() - 1</code>.
     * @param     index  the index of the desired character.
     * @return    the desired character.
     * @exception StringIndexOutOfRangeException 
     *              if the index is not in the range <code>0</code> 
     *              to <code>length()-1</code>.
     * @see       java.lang.Character#charValue()
    public char charAt(int index) {


To shorten or simplify the javadoc command, you may specify one or more files that themselves contain one source filename or package name per line. On the command line, use the '@' character with the filename to specify it as a file list. When javadoc encounters an argument beginning with the character `@', it operates on the names in that file as if they had been on the command line.

For example, you can list all of the package names in a file named packages. This file might look like:

You could then run javadoc with:
     C:> javadoc -d apidocs @packages


The javadoc tool uses doclets to determine its output. Javadoc uses the default standard doclet unless a custom doclet is specified with the -doclet option. Javadoc provides a set of command-line options that can be used with any doclet -- these options are described below under the sub-heading Javadoc Options. The standard doclet provides an additional set of command-line options that are described below under the sub-heading Options Provided by the Standard Doclet. All option names are case-insensitive, though their arguments can be case-sensitive.

The options are:


Javadoc Options

-overview  path\filename
Specifies that javadoc should retrieve the text for the overview documentation from the "source" file specified by path\filename and place it on the Overview page (overview-summary.html). The path\filename is relative to the -sourcepath.

While you can use any name you want for filename and place it anywhere you want for path, a typical thing to do is to name it overview.html and place it in the source tree at the directory that contains the topmost package directories. In this location, no path is needed when documenting packages, since -sourcepath will point to this file. For example, if the source tree for the java.lang package is C:\src\classes\java\lang\, then you could place the overview file at C:\src\classes\overview.html. See Real World Example.

For information about the file specified by path\filename, see overview comment file.

Under certain circumstances, the overview page is not generated. For more information about this, see HTML Frames.

Shows only public classes and members.

Shows only protected and public classes and members. This is the default.

Shows only package, protected, and public classes and members.

Shows all classes and members.

Displays the online help, which lists these javadoc and doclet command line options.

-doclet  class
Specifies the class file that starts the doclet used in generating the documentation. This doclet defines the content and formats the output. If the -doclet option is not used, javadoc uses the standard doclet for generating the default HTML format. This class must contain the start(Root) method. The path to this starting class is defined by the -docletpath option.

-docletpath  classpathlist
Specifies the path to the doclet class file that is specified with the -doclet option. This option is not necessary if the doclet is already in the search path.

Generates the documentation with the appearance and functionality of documentation generated by Javadoc 1.1. That is, the pages have a gray background, use images for headers, have bulleted lists instead of tables, have a flat destination directory structure, do not contain inherited API, do not use HTML frames, and do not support inner classes. This option also automatically splits the index into a separate file for each letter of the alphabet. If you want this appearance, this option has the advantage over javadoc 1.1 of having some bugs fixed.

Not all options work with the -1.1 option. To find out which other options are available, execute:

  C:> javadoc -1.1 -help
The -footer option shown in this list is functionally the same as the -bottom option described elsewhere on this page. The -title option is functionally the same as -doctitle.

-sourcepath  sourcepathlist
Specifies the search paths for finding source files (.java) when passing package names into the javadoc command. Note that you can use the sourcepath option only when specifying package names with the javadoc command -- it will not locate .java files passed into the javadoc command. If -sourcepath is omitted, javadoc uses the class path to find the source files (see -classpath).

Set sourcepathlist to the root directory of the source tree for the package you are documenting. For example, suppose you want to document a package called com.mypackage whose source files are located at:

In this case you would specify the sourcepath to C:\user\src, the directory that contains com\mypackage, and then supply the package name com.mypackage:
javadoc -sourcepath C:\user\src com.mypackage
This is easy to remember by noticing that if you concatenate the value of sourcepath and the package name together and change the dot to a slash "\", you end up with the full path to the package: C:\user\src\com\mypackage.

-classpath  classpathlist
Specifies the paths where javadoc will look for referenced classes -- these are the documented classes plus any classes referenced by those classes. Javadoc will search in all subdirectories of the specified paths. The classpathlist can contain multiple paths by separating them with a semicolon. Follow the instructions in class path documentation for specifying classpathlist.

If -sourcepath is omitted, Javadoc uses -classpath to find the source files as well as class files (for backward compatibility). Therefore, if you want to search for source and class files in separate paths, use both -sourcepath and -classpath.

For example, if you want to document com.mypackage, whose classes reside in the directory C:\user\src\com\mypackage, and this package relies on a library in C:\user\lib, you would specify:

  C:> javadoc -classpath \user\lib -sourcepath \user\src com.mypackage
As with other tools, if you do not specify -classpath, Javadoc uses the CLASSPATH environment variable, if it is set. If both are not set, Javadoc searches for classes from the current directory.

For an in-depth description of how Javadoc uses -classpath to find user classes as it relates to extension classes and bootstrap classes, see How Classes Are Found.

-bootclasspath  classpathlist
Specifies the paths where the boot classes reside. These are nominally the Java platform classes. The bootclasspath is part of the search path Javadoc will use to look up source and class files. See How Classes Are Found. for more details. Separate directories in classpathlist with semicolons (;).

-extdirs  dirlist
Specifies the directories where extension classes reside. These are any classes that use the Java Extension mechanism. The extdirs is part of the search path Javadoc will use to look up source and class files. See -classpath (above) for more details. Separate directories in dirlist with semicolons (;).

Provides more detailed messages while javadoc is running. Without the verbose option, messages appear for loading the source files, generating the documentation (one message per source file), and sorting. The verbose option causes the printing of additional messages specifying the number of milliseconds to parse each java source file.

-locale  language_country_variant
Specifies the locale that javadoc uses when generating documentation. The argument is the name of the locale, as described in java.util.Locale documentation, such as en_US (English, United States) or en_US_WIN (Windows variant).

Specifying a locale causes javadoc to choose the resource files of that locale for messages (strings in the navigation bar, headings for lists and tables, help file contents, comments in stylesheet.css, and so forth). It also specifies the sorting order for lists sorted alphabetically, and the sentence separator to determine the end of the first sentence. It does not determine the locale of the doc comment text specified in the source files of the documented classes.

-encoding  name
Specifies the source file encoding name, such as EUCJIS/SJIS. If this option is not specified, the platform default converter is used.

Passes flag directly to the runtime system java that runs javadoc. Notice there must be no space between the J and the flag. For example, if you need to ensure that the system sets aside 32 megabytes of memory in which to process the generated documentation, then you would use this flag as follows:

   C:> javadoc -J-Xmx32m -J-Xms32m com.mypackage

Options Provided by the Standard Doclet

-d  directory
Specifies the destination directory where javadoc saves the generated HTML files. (The "d" means "destination.") Omitting this option causes the files to be saved to the current directory. The value directory can be absolute or relative to the current working directory. For example, the following generates the documentation for the com.mypackage package and saves the results in the C:\user\doc\ directory:
  C:> javadoc -d \user\doc com.mypackage

Includes one "Use" page for each documented class and package. The page describes what packages, classes, methods, constructors and fields use any API of the given class or package. Given class C, things that use class C would include subclasses of C, fields declared as C, methods that return C, and methods and constructors with parameters of type C.

For example, let's look at what might appear on the "Use" page for String. The getName() method in the java.awt.Font class returns type String. Therefore, getName() uses String, and you will find that method on the "Use" page for String.

Note that this documents only uses of the API, not the implementation. If a method uses String in its implementation but does not take a string as an argument or return a string, that is not considered a "use" of String.

You can access the generated "Use" page by first going to the class or package, then clicking on the "Use" link in the navigation bar.

Includes the @version text in the generated docs. This text is omitted by default.

Includes the @author text in the generated docs.

Splits the index file into multiple files, alphabetically, one file per letter, plus a file for any index entries that start with non-alphabetical characters.

-windowtitle  title
Specifies the title to be placed in the HTML <title> tag. This appears in the window title and in any browser bookmarks (favorite places) that someone creates for this page. This title should not contain any HTML tags, as the browser will not properly interpret them. Any internal quotation marks within title may have to be escaped. If -windowtitle is omitted, Javadoc uses the value of -doctitle for this option.

-doctitle  title
Specifies the title to be placed near the top of the overview summary file. The title will be placed as a centered, level-one heading directly beneath the upper navigation bar. The title may contain html tags and white space, though if it does, it must be enclosed in quotes. Any internal quotation marks within title may have to be escaped.

-title  title
This option no longer exists. It existed only in Beta versions of Javadoc 1.2. It has been renamed to -doctitle. This option is being renamed to make it clear that it defines the document title rather than the window title.

-header  header
Specifies the header text to be placed at the top of each output file. The header will be placed to the right of the upper navigation bar. header may contain HTML tags and white space, though if it does, it must be enclosed in quotes. Any internal quotation marks within header may have to be escaped.

-footer  footer
Specifies the footer text to be placed at the bottom of each output file. The footer will be placed to the right of the lower navigation bar. footer may contain html tags and white space, though if it does, it must be enclosed in quotes. Any internal quotation marks within footer may have to be escaped.

-bottom  text
Specifies the text to be placed at the bottom of each output file. The text will be placed at the bottom of the page, below the lower navigation bar. The text may contain HTML tags and white space, though if it does, it must be enclosed in quotes. Any internal quotation marks within text may have to be escaped.

-link  docURL
Creates links to already existing javadoc-generated documentation of external referenced classes. The argument docURL is the URL for the javadoc-generated external documentation you want to link to. This location can be a relative or absolute URL.

In other words, this option enables you to link to classes referenced to by your code but not being documented in the current javadoc run. For these links to go to valid pages, you must know where those HTML pages are located, and specify that location with docURL. This allows, for instance, third party documentation to link to java.* documentation on Another use is to for cross-links between sets of packages: Execute javadoc on one set of packages, then run javadoc again on another set of packages, creating links both ways between both sets. A third use is as a "hack" to update docs: Execute javadoc on a full set of packages, then run javadoc again on only the smaller set of changed packages, so that the updated files can be inserted back into the original set. (This is done to save time, but can be tricky -- if you add or remove API from the subset, there will be missing or broken links in the index.)

Use the -link option as follows:

  • Omit the -link option for javadoc to create links only to API within the documentation it is generating in the current run. (Without the -link option, Javadoc does not create links to documentation for external references, because it does not know if (or where) that documentation exists.)

  • Include the -link option for javadoc to also create links to documentation at location docURL for external referenced classes.

Note that if the URL is on the World Wide Web, javadoc must have a web connection in order to access the package-list when generating the documentation. If you do not have access, use -linkoffline instead.

Package List - The -link option requires that a file named package-list, which is generated by Javadoc, exist at the URL you specify with -link. The package-list file is a simple text file that lists the names of packages documented at that location. How Javadoc uses the package list is described below.

For example, the package list for the Java Platform 1.2 API is located at and starts out as follows:


When javadoc is run without the -link option, as it generates documentation, when it encounters a name that belongs to an external referenced class, it prints the name with no link. However, when the -link option is used, Javadoc searches the package-list file at the specified docURL location for that package name. If it finds the package name, it prefixes the name with that URL. (If the URL is relative and the -d destination directory option is relative, Javadoc prepends the relative path of the destination directory to the URL so that links will work from the destination directory.)

In order for there to be no broken links, all of the documentation for the external references must exist at the specified URLs. Javadoc will not check that these pages exist -- only that the package-list exists.

The package-list file is created but is empty if the argument to javadoc is source files rather than packages.

Example - For example, the following command causes Javadoc to look for a package-list file at the given URL, reads in the package names in that file, and then uses the given URL when adding links to API in those external packages:

  C:> javadoc -link com.mypackage
Multiple Links - You can supply multiple -link options to link to any number of external generated documents.   Known Bug - Javadoc 1.2 has a known bug which prevents you from supplying more than one -link command. This should be fixed in a future release.

Specify a different link option for each external document to link to:

   C:> javadoc -link docURL1 -link docURL2 ... -link docURLn com.mypackage

where docURL1docURL2,  ... docURLn point respectively to the roots of external documents, each of which contains a file named package-list.

Cross-links - Note that "bootstrapping" may be required when cross-linking two or more documents that have not previously been generated. In other words, if package-list does not exist for either document, when you run javadoc on the first document, the package-list will not yet exist for the second document. Therefore, to create the external links, you must re-generate the first document after generating the second document.

In this case, the purpose of first generating a document is to create its package-list (or you can create it by hand it if you're certain of the package names). Then generate the second document with its external links. Javadoc prints a warning if a needed external package-list file does not exist.

Updating docs - The third use for -link option is useful if your project has dozens or hundreds of packages, if you have already run javadoc on the entire tree, and now, in a separate run, you want to quickly make some small changes and re-run javadoc on just a small portion of the source tree. This is somewhat of a hack in that it works properly only if your changes are only to doc comments and not to signatures. If you were to add, remove or change any signatures from the source code, then broken links could show up in the index, package tree, inherited member lists, use page, or other places.

First, you create a new destination directory for this new small run and set -link and -d to that same relative path: If the original docs are in a directory named html:

  C:> javadoc -d update -linkoffline . html com.mypackage
When javadoc is done, copy these generated files in update over the original files in html.

Background information: In general, when javadoc runs, it has the potential to generate links for names that appear throughout its generated pages: in signatures, @see tags, {@link} tags, summaries, hierarchies, the overview, and the index. Some of these links will go to pages generated in the current run, while other links will potentially go to pages not generated in the current run.

-linkoffline  docURL  packagelistURL
This option creates links to documentation for names of external reference classes where:

  • docURL is the URL for the root location of the javadoc-generated external documentation you want to link to. This location can be a relative or absolute URL.

  • packagelistURL is the URL for the directory containing the package-list file for that documentation. (You can create this file yourself by hand if you need to.)

This option is a variation on -link. You can use -linkoffline if the packages-list file does not exist at the docURL location at the time you run javadoc. If you know what package names your document will link to, and where that document will reside, it lets you generate documentation with those external links prior to when the package-list file actually exists at that location. This enables you to use your own copy of package-list to generate the documentation with the proper links.

This is useful when you need to generate documentation that links to new external documentation whose package names you know, but is not yet published. This enables two companies to release their documentation simultaneously. It also allows you to generate documentation that links to external documentation that has no package-list file (perhaps because it was generated with Javadoc 1.0, 1.1 or up to 1.2 Beta3).

Note that this option does not require access to the documentation URL when you run javadoc. Thus, if the URL is on the World Wide Web, you do not need a web connection when generating the documentation.

As shown below, to use this option, specify docURL1, the location of the javadoc-generated documentation for external referenced classes, and packagelistURL1, the location of its package-list file. If they have the same location, you can just use -link instead. Include -linkoffline once for each generated document you want to refer to:

C:> javadoc -linkoffline docURL1 packagelistURL1 -linkoffline docURL2 packagelistURL2

For example, the following command adds links using the URL given as the first argument, and looks for the package-list file at the path given by the second argument.

C:> javadoc -linkoffline /usr/web/work/products/jdk/1.2/docs/api/

-group  groupheading  packagepattern:packagepattern:...
Separates packages on the overview page into whatever groups you specify, one group per table. You specify each group with a different -group option. The groups appear on the page in the order specified on the command line; packages are alphabetized within a group. For a given -group option, the packages matching the list of packagepattern expressions appear in a table with the heading groupheading.

  • groupheading can be any text, and can include white space. This text is placed in the table heading for the group.

  • packagepattern can be any package name, or can be the start of any package name followed by an asterisk (*). The asterisk is a wildcard meaning "match any characters". This is the only wildcard allowed. Multiple patterns can be included in a group by separating them with semicolons (;).
NOTE: If using an asterisk in a pattern or pattern list, the pattern list must be inside quotes, such as "java.lang*:java.util"

If you do not supply any -group option, all packages are placed in one group with the heading "Packages". If the all groups do not include all documented packages, any leftover packages appear in a separate group with the heading "Other Packages".

For example, the following option separates the four documented packages into core, extension and other packages. Notice the trailing "dot" does not appear in "java.lang*" -- including the dot, such as "java.lang.*" would omit the java.lang package.

  C:> javadoc -group "Core Packages" "java.lang*:java.util"
            -group "Extension Packages" "javax.*"
            java.lang java.lang.reflect java.util javax.servlet
This results in the groupings:
Core Packages
Extension Packages
Other Packages

Prevents the generation of any deprecated API at all in the documentation. This does what -nodeprecatedlist does, plus it does not generate any deprecated API throughout the rest of the documentation. This is useful when writing code and you don't want to be distracted by the deprecated code.

Prevents the generation of the file containing the list of deprecated APIs (deprecated-list.html) and the link in the navigation bar to that page. (However, javadoc continues to generate the deprecated API throughout the rest of the document.) This is useful if your source code contains no deprecated API, and you want to make the navigation bar cleaner.

Omits the class/interface hierarchy from the generated docs. The hierarchy is produced by default.

Omits the index from the generated docs. The index is produced by default.

Omits the HELP link in the navigation bars at the top and bottom of each page of output.

Prevents the generation of the navigation bar, header and footer, otherwise found at the top and bottom of the generated pages. Has no affect on the "bottom" option. The -nonavbar option is useful when you are interested only in the content and have no need for navigation, such as converting the files to PostScript or PDF for print only.

-helpfile  path\filename
Specifies the path of an alternate help file path\filename that the HELP link in the top and bottom navigation bars link to. Without this option, Javadoc automatically creates a help file help-doc.html that is hard-coded in Javadoc. This option enables you to override this default. The filename can be any name and is not restricted to help-doc.html -- Javadoc will adjust the links in the navigation bar accordingly. For example:
  C:> javadoc -helpfile C:\user\myhelp.html java.awt
-stylesheetfile  path\filename
Specifies the path of an alternate HTML stylesheet file. Without this option, Javadoc automatically creates a stylesheet file stylesheet.css that is hard-coded in Javadoc. This option enables you to override this default. The filename can be any name and is not restricted to stylesheet.css. For example:
  C:> javadoc -stylesheetfile C:\user\mystylesheet.css com.mypackage
-docencoding  name
Specifies the encoding of the output HTML files.


You can run javadoc on entire packages or individual classes. Each package name has a corresponding directory name. In the following examples, the source files are located at C:\home\src\java\awt\*java. The destination directory is C:\home\html.

Documenting One or More Packages

To document a package, the source files (*.java) for that package must be located in a directory having the same name as the package. If a package name is made up of several identifiers (separated by dots), each identifier represents a different directory. Thus, all java.awt classes must reside in a directory named java\awt\. You can run javadoc either of the following two ways -- by changing directories (with cd) or by using sourcepath option. You cannot use wildcards to specify groups of packages.

Both cases generate HTML-formatted documentation for the public and protected classes and interfaces in packages java.awt and java.awt.event and save the HTML files in the specified destination directory (C:\home\html). Because two or more packages are being generated, the document has three frames -- for the list of packages, the list of classes, and the main page.

Documenting One or More Classes

To document one or more source files (.java), the files do not have to be in any particular directories. You can run javadoc either of the following two ways -- by changing directories (with cd) or by fully-specifying the path to the .java files. The -sourcepath option does not work when documenting source files. You can use command line wildcards, such as asterisk (*), to specify groups of classes.

Documenting Both Packages and Classes

You can document entire packages and individual classes at the same time. Here's an example that mixes two of the previous examples. You can use -sourcepath for the path to the packages but not for the path to the individual classes.
  C:> javadoc -d C:\home\html -sourcepath C:\home\src java.awt C:\home\src\java\applet\
This example generates HTML-formatted documentation for the package java.awt and class Applet. (Javadoc determines the package name for Applet from the package declaration, if any, in the source file.)


Javadoc has many useful options, some of which are more commonly used than others. Here is effectively the command we use to run javadoc on the Java platform API, using makefile variables (except not all packages to be documented are listed).
javadoc -sourcepath /jdk/src/share/classes \   /* Path for source files          */
        -d /jdk/build/api                  \   /* Destination directory          */
        -use                               \   /* Adds "Use" files               */
        -splitIndex                        \   /* Splits index A-Z               */
        -windowtitle $(WINDOWTITLE)        \   /* Adds a window title            */
        -doctitle $(DOCTITLE)              \   /* Adds a doc title               */
        -header $(HEADER)                  \   /* Adds running header text       */
        -bottom $(BOTTOM)                  \   /* Adds text at bottom            */
        -group $(GROUPCORE)                \   /* Core heading for overview page */
        -group $(GROUPEXT)                 \   /* Ext heading for overview page  */
        -overview overview-core.html       \   /* For overview text              */
        -J-Xmx180m                         \   /* For 180MB memory               */
        java.lang java.lang.reflect        \   /* Packages to document           */
        java.util         \
WINDOWTITLE = 'Java Platform 1.2 Final API Specification'
DOCTITLE = 'Java<sup><font size="-2">TM</font></sup> Platform 1.2 Final API Specification'
HEADER = '<b>Java Platform 1.2</b><br><font size="-1">Final</font>'
BOTTOM = '<font size="-1"><a href="">Submit
    a bug or feature</a><br><br>Java is a trademark or registered trademark 
    of Sun Microsystems, Inc. in the US and other countries.<br>Copyright 1993-1998    
    Sun Microsystems, Inc. 901 San Antonio Road,<br>Palo Alto, California, 94303, U.S.A.  
    All Rights Reserved.</font>'
GROUPCORE = '"Core Packages" "java.**:org.omg.*"
GROUPEXT  = '"Extension Packages" "javax.*"'

If you omit the -windowtitle option, javadoc copies the doc title to the window title. The -windowtitle option would not be needed except for the fact that the doc title contains HTML tags,

If you omit the -footer option, as done here, javadoc copies the header text to the footer.

Other important options are -classpath and -link.


Environment variable that provides the path which javadoc uses to find user class files. This environment variable is overridden by the -classpath option. Separate directories with a semi-colon, for example:


Please send comments to: