Sets
Relations
Correspondences
Ordered Sets
Lattices
Graphs
Powersets
Binary Strings
Logic
AIA
Greek
Glossary
Abstracts
Argument
Inquiry Cycle
Legal Relations
Presentations
Elicitation
Glossaries
Goals
i*
SCR
Tracing
Design Patterns
Javadoc
Java Packages
Java Types
package.html
filejavadoc
commandjavadoc
-options and arguments
javadoc
is a command-line tool
for extracting special comments
(called doc comments)
from java source files
and generating an easy-to-use HTML file tree
containing them.
Doc comments begin with /**
and immediately precede a
class,
interface,
constructor,
method,
or
field definition
are extracted and processed.
The comments can include standard
HTML markup
and javadoc
@tags
.
The
Java API Specification
is an example of what javadoc
produces.
The javadoc
tool is part of the free Sun SDK distribution.
The HTML output generated by javadoc
is organized like java source is:
The overview file for the output from a javadoc compilation can appear in a file of any name; the file name is specified in the -overview option to the javadoc command.
The file may contain HTML elements and
inline {@tags}
,
and may conclude with one or more:
The file should begin with an HTML <body> tag and end with an HTML >/body> tag.
package.html
file
The summary describing a package
must appear in a file named package.html
in the package directory along with the java files for the class.
The format of the package.html
file
is the same as that of the overview file.
Doc comments describe classes, interfaces, fields, constructors, and methods.
Each doc comment consists of:
/**
{@tags}
but no
block @tags
@tags
*/
Text in the description and tag blocks can contain HTML format elements.
A doc comment may be all on one line:
/** All on one line -- but still a doc comment. */ |
|
or span several lines:
/** Spans several lines -- still a doc comment */ |
The second and later lines of a multi-line doc comment
/** * For that 'retro' * FORTRAN look. */may begin with whitespace and an asterisk, which javadoc discards. |
The first sentence of each class, interface field, constructor, and method doc comment is reused in the indexes, so this sentence should summarize the thing described, concisely but completely.
The recommended grammatical form for the first line of the doc comment for class X is 'An X is ...' or an equivalent sentence.
The recommended form for a constructor or method is that it begin with a verb and be the completion of a sentence that would begin 'This constructor ...' or 'This method ...', respectively.
For example, the java.lang
package and
java.lang.String
doc comments begin:
package | 'Provides classes that are fundamental to the design of the Java programming language.' |
---|---|
class | 'The String class represents character strings.' |
constructor | 'Initializes a newly created String object so that it represents an empty character sequence.' |
method | 'Returns the character at the specified index.' |
The doc comment describing a class or interface
must appear immediately before the class or interface.
Its first sentence should summarize the class or interface
concisely but completely;
a good form for class or interface X is
'An X is a ...', 'An X represents a ...', or
'A ...' or 'Represents a ....'
It may include inline {@tags}
and may conclude with one or more:
The doc comment describing a field
must appear immediately before the field declaration.
It may include inline {@tags}
.
Its first sentence should summarize the field concisely but completely.
The doc comment describing a method or constructor
must appear immediately before the field declaration.
Its first sentence should summarize the method or constructor
concisely but completely,
and should begin with a verb and complete 'This constructor ...'
or 'This method ...', respectively.
Examples are
'Initializes a newly created String object so that it represents
an empty character sequence' or
'Returns the character at the specified index,'
respectively.
The doc comment
may include inline {@tags}
,
and should end with
@param
block tag for each of the
method or constructor's parameters,
@return
block tag,
if it is a method whose type is not void
,
and
@throws
block tag
for each exception the method or constructor
can throw (whether or not the method or constructor declares this).
The doc comments of a class or interface may be inherited by a class that extends or implements it, respectively.
If the subclass does not provide its own implementation of a method, the generated description of it lists the inherited methods with links to their descriptions.
If the subclass implements a method of its superclass or interface, but the java file does not contain a doc comment for it, the doc comment of the superclass or interface is inherited and appears word-for-word in the description of the subclass.
String
class/** The String class represents character strings. All string literals in Java programs, such as <code>'abc'</code>, are implemented as instances of this class. <p> Strings are constant; their values cannot be changed after they are created. String buffers support mutable strings. Because String objects are immutable they can be shared. For example: <pre> String str = 'abc'; </pre> <p> is equivalent to: <pre> char data[] = {'a', 'b', 'c'}; String str = new String(data); </pre> <p> The class <code>String</code> includes methods for examining individual characters of the sequence, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase or to lowercase. Case mapping is based on the Unicode Standard version specified by the {@link Character} class. <p> Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a {@link NullPointerException} to be thrown. @see Object.toString() @see StringBuffer @see StringBuilder @see Charset @see Serialized Form */ public class String { ...
CASE_INSENSITIVE_ORDER
field/** A Comparator that orders <code>String</code> objects as by <code>compareToIgnoreCase</code>. This comparator is serializable. <p> Note that this Comparator does <i>not</i> take locale into account, and will result in an unsatisfactory ordering for certain locales. The java.text package provides <i>Collators</i> to allow locale-sensitive ordering. @see Collator.compare(String, String) */ public static final Comparator<String> CASE_INSENSITIVE_ORDER;
String(String)
constructor/** Initializes a newly created <code>String</code> object so that it represents the same sequence of characters as the argument; in other words, the newly created string is a copy of the argument string. Unless an explicit copy of <code>original</code> is needed, use of this constructor is unnecessary since Strings are immutable. @param original a String. */ public String(String original) { ...
charAt(int)
method/** Returns the <code>char</code> value at the specified index. An index ranges from <code>0</code> to <code>length() - 1</code>. The first char value of the sequence is at index <code>0</code>, the next at index <code>1</code>, and so on, as for array indexing. @param index the index of the char value. @return the char value at the specified <code>index</code> of this string. The first <code>char</code> value is at index <code>0</code>. @throws IndexOutOfBoundsException if the index argument is negative or not less than the length of this string. */ public char charAt(int index) { ...
A block tag has the form @tag
followed by text.
Block tags can only appear after the main description of a doc comment.
An inline tag has the form {@tag ...}
.
Inline tags may appear anywhere in a doc comment.
The most useful javadoc tags are:
In same package and class |
---|
{@link #field} |
{@link #method} |
{@link #method(Type,Type,...)} |
In same package, different class |
{@link Class#field} |
{@link Class#method} |
{@link Class#method(Type,Type,...)} |
{@link Class} |
In another package, or frompackage.html or overview |
{@link package.Class#field} |
{@link package.Class#method} |
{@link package.Class#method(Type,...)} |
{@link package.Class} |
{@link package} |
If a label is given, it is used as the label for the link. If no label is given, the appropriately-qualified name of the item being linked to is used as the label for the link.
{@link ...}
displays the link text in code
font,
while
{@linkplain ...}
displays it in plain font.
Otherwise they behave the same.
@see 'string' | Adds an entry with the string |
---|---|
@see <a href='URL#label'>label</a> | Adds an entry with that link. |
@see package.class#member label | Adds an entry with a link to the specified documentation.
See {@link}
for the possibilities. |
package.html
file
prevents this for all classes in the package.
See Sun's javadoc documentation for more tags.
javadoc
commandThe javadoc command line synopsis is
javadoc [options] [packages] [sourcefiles] [@files]
Examples in this section are adapted from Sun's examples.
javadoc
-options and argumentsThe following options are particularly useful. See Sun's javadoc documentation for more.
-sourcepath
,
then those packages in packagelist are
excluded.
-link
external-doc-URL
option may be given.
Option | Which classes, etc., are documented | |||
---|---|---|---|---|
-public | public | |||
-protected | public | protected | ||
-package | public | protected | (package) | |
-private | public | protected | (package) | private |
javadoc
creates a file
stylesheet.css
in the documenation directory.
To generate documentation for a package,
list the package names.
If the package name is two or more levels deep,
the directory names are separated by dot (.)
as always in Java.
javadoc will look for each package's source files
in the package directory,
and will look for the package directory
on the -sourcepath
path,
or in the current directory if -sourcepath
is not given.
Examples:
javadoc -d /home/html -sourcepath
/home/src java.awt java.awt.event
javadoc -d /home/html java.awt java.awt.event
To generate documentation for specific source files,
list the source file names
(using slashes rather than dots to separate directories,
and including the .java
suffix).
You can include both package names and source file names on the same command line.
Examples:
javadoc -d /home/html Button.java Canvas.java Graphics*.java
javadoc -d /home/html
java/awt/Button.java java/applet/Applet.java
javadoc -d /home/html
/home/src/java/awt/Button.java /home/src/java/awt/Graphics*.java
javadoc -d /home/html
-sourcepath /home/src java.awt /home/src/java/applet/Applet.java
An @file
('at-file') is a file containing javadoc command line
options and arguments.
To run javadoc
using options and arguments
in two files whose pathname from the current directory
are optsFile1
and package/OptsFile2
,
put @optsFile1
@package/OptsFile
on the javadoc
command line.