Documenting Java Code: Javadoc: The Tool and The Legend
Documenting Java Code: Javadoc: The Tool and The Legend
Comments in Java
One Liners: //
The first line is indented to line up with the code below the comment, and starts
with the begin-comment symbol (/**) followed by a return
Subsequent lines start with an asterisk *. They are indented an additional space so
the asterisks line up. A space separates the asterisk from the descriptive text or tag
that follows it.
Insert a blank comment line between the description and the list of tags, as shown.
The last line begins with the end-comment symbol (*/) indented so the asterisks
line up and followed by a return.
Note that the end-comment symbol contains
only a single asterisk (*).
/**
* This is the description part of a doc comment
*
* @tag Comment for the tag
*/
First Sentence
The Javadoc tool copies this first sentence to the appropriate member,
class/interface or package summary
This sentence ends at the first period that is followed by a blank, tab, or line
terminator, or at the first tag (as defined below). For example, this first
sentence ends at "Prof.":
/**
* This is a simulation of Prof. Knuth's MIX computer.
*/
you can work around this by typing an HTML meta-character such as "&" or
"<" immediately after the period, such as: /**
* This is a simulation of Prof. Knuth's MIX computer.
*/
Tagged Paragraphs
Begin with @ followed by
keyword
End at the next tag or end of the
comment
Identify information that has
routine structure
@see
@author
@version
@param
Parameters should be
documented in the order in
which they are declared
@return
@exception (@throws)
@deprecated
@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".
JavaDoc Example
/**
* The root of the Class hierarchy. Every Class in the
* system has Object as its ultimate parent. Every variable
* and method defined here is available in every Object.
* @see
Class
* @version 1.37, 26 Jun 1996
*/
public class Object {
/**
* Compares two Objects for equality.
* Returns a boolean that indicates whether this Object
* is equivalent to the specified Object. This method is
* used when an Object is stored in a hashtable.
* @param obj
the Object to compare with
* @return
true if these Objects are equal;
*
false otherwise.
* @see
java.util.Hashtable
*/
Running Javadoc
Synopsis:
javadoc [ options ] [ packagenames
] [ sourcefiles ] [ @files ]
Example
javadoc -sourcepath
/java/my/src/share/classes -d
/java/my/api me.pack1 me.pack2
Links
http://java.sun.com/j2se/javadoc/
writingdoccomments/index.html
http://java.sun.com/docs/books/jl
s/html/18.doc.html
http://java.sun.com/products/jdk/
1.2/docs/tooldocs/win32/javadoc
.html