Documentation With Javadoc
Documentation With Javadoc
JavaDoc
javadoc utility makes writing and maintaining code
documentation up-to-date easier!
Ships with JDK
@version release
Indicate the version of the software containing this
class
Used in: Class, Interface
JavaDoc Tags
@see target
Point the reader at something else relevant to read, like another class or
a specific method
Inserts a link pointing to the target
Used in: All
@deprecated text
Marks the entity as deprecated and points the reader to what they
should use instead via an @see tag
Used in: All
@see tag
Points to another package, class, method, field or even URL
javadoc creates a link
The syntax for the text after @see depends upon what you're
pointing to:
@see package Link to package
@see classname Link to classname in the current package
@see package.classname Link to classname in another package
@see #method Link to method in the current class
@see #method(type) Link to methodwith argument
@see classname#method Link to method in another class
Method in a class in a different package?
@see <a href=url>text</a> Link to URL
Examples
//same class entities //different package
@see #field entities
@see#Constructor(Type,...) @see package
@see #method(Type, @see package.Class
Type,...) @see package.Class#field
@see
//same package entities package.Class#Constructor(
@see Class Type,...)
@see Class#field @see
package.Class#method(Type,
@seeClass#Constructor(Type Type,...)
,...)
@see //URL
Class#method(Type,...) @see <a href="spec.html#section">Java
Spec</a>
JavaDoc Tags
@param <name of parameter> short
description of parameter
Describe the named parameter to this method
Skip this tag if the method has no parameters
Used in: Method
E.g. @param size number of elements in the
array
@return text
Describe the value returned by this method
Skip this tag if the method has no return value
Appears after @param tag(s)
Used in: Method
Example
/**
* Validates a chess move.
*
* @author John Doofus
* @param theFromLoc Location of piece being moved
* @param theRank Rank of piece being moved
* @param theToLoc Location of destination square
* @return true if a valid chess move or false if invalid
*/
boolean isValidMove(int theFromLoc, int theRank, int
theToLoc) { ... }
JavaDoc Tags
@throws <name of exception> description
of circumstances under which exception
is thrown
Describes the named uncaught checked or explicitly
thrown checked/unchecked exception
Skip this tag if the method throws no exceptions
Should follow @param and @return tags
If method throws more than one exception
they should appear in alphabetical order by exception name
Used in
Method
@throws FileNotFoundException raised if the
user does not specify a valid file name
Checked vs. Unchecked
You only advertise (via throws on method header) (or catch) and include
@throws for
(P.S. throws on method header exception is not handled in the method but
forwarded to the invoker)
checked exceptions
explicitly thrown unchecked ones
Unchecked exceptions :
beyond your control (Error) or result from a condition that you should not have
allowed in the first place (RuntimeException)
are subclasses of
RuntimeException (e.g. ArrayIndexOutOfBoundException)
Error (e.g. OutOfMemoryError)
The Java compiler checks all exception handling, except exceptions represented
by (subclasses of) Error and RuntimeException
Checked vs. Unchecked
Checked exceptions:
represent invalid conditions in areas outside the immediate
control of the program
E.g. database problems, network outages, or absent files
http://java.sun.com/j2se/javadoc/wr
itingdoccomments/
Minimum Requirements
Class (or package) Method/Constructor
@author <ordered>
@version @param
@see @return
@deprecated @throws
</ordered>
@see
Field
@deprecated (followed by
@see
another @see sometimes)
@deprecated (followed by
another @see sometimes)
JavaDoc using Eclipse
Code formatter
Highlight code
Source > Format
JavaDoc comment generator
Select the project or file in Package Explorer
Project > Generate Javadoc
Follow wizard