This article is written like a manual or guide.(August 2023) |
Javadoc is a documentation generator created by Sun Microsystems for the Java language (now owned by Oracle Corporation) for generating API documentation in HTML format from Java source code. The HTML format is used for adding the convenience of being able to hyperlink related documents together.
The "doc comments" format used by Javadoc is the de facto industry standard for documenting Java classes. Some IDEs, like IntelliJ IDEA, NetBeans and Eclipse, automatically generate Javadoc templates. Many file editors assist the user in producing Javadoc source and use the Javadoc info as internal references for the programmer.
Javadoc also provides an API for creating doclets and taglets, which allows users to analyze the structure of a Java application. This is how JDiff can generate reports of what changed between two versions of an API.
Javadoc does not affect performance in Java as all comments are removed at compilation time. Writing comments and Javadoc is for better understanding the code and thus better maintaining it.
Javadoc was an early Java language documentation generator. Prior to the use of documentation generators it was customary to use technical writers who would typically write only standalone documentation for the software, but it was much harder to keep this documentation in sync with the software itself.
Javadoc has been used by Java since the first release, and is usually updated upon every new release of the Java Development Kit.
The @field
syntax of Javadoc has been emulated by documentation systems for other languages, including the cross-language Doxygen, the JSDoc system for JavaScript, EDoc for Erlang, and Apple's HeaderDoc.
A Javadoc comment is set off from code by standard multi-line comment tags /*
and */
. The opening tag (called begin-comment delimiter), has an extra asterisk, as in /**
.
Most Javadoc comments are imbedded inside
/** ... */
tags. The Javadoc comment block is positioned immediately above the items
without any separating newline, and below any import statements.The class declaration usually
contains:
// import statements
/**
* @author Firstname Lastname <address @ example.com>
* @version 1.6 (current version number of program)
* @since 1.2 (the version of the package this class was first added to)
*/
public class Test {
// class body
}
Documentation comments for methods usually contain a short, concise, one line description to
explain what the item does, followed by a longer description, and lastly a tag section that lists accepted input arguments and return values of the method. The
Javadoc is treated as HTML, so a "<p>
" paragraph break tag can be used to denote multiple paragraphs.
/**
* Short one line description. (1)
* <p>
* Longer description. If there were any, it would be (2)
* here.
* <p>
* And even more explanations to follow in consecutive
* paragraphs separated by HTML paragraph breaks.
*
* @param variable Description text text text. (3)
* @return Description text text text.
*/
public int methodName (...) {
// method body with a return statement
}
Variables are documented similarly to methods, but often lack the tags at the end of the comment.
/**
* Description of the variable here.
*/
private int debug = 0;
It is not recommended[6] to define multiple variables in a single documentation comment, as Javadoc reads each variable and places them separately to the generated HTML page with the same documentation comment that is copied for all fields.
/**
* The horizontal and vertical distances of point (x,y)
*/
public int x, y; // AVOID
Instead, it is recommended to write and document each variable separately:
/**
* The horizontal distance of point.
*/
public int x;
/**
* The vertical distance of point.
*/
public int y;
This section's factual accuracy may be compromised due to out-of-date information. The reason given is: Should be updated according to the official documentation.(November 2023) |
Some of the available Javadoc tags[7] are listed in the table below:
Tag & Parameter | Usage | Applies to | Since |
---|---|---|---|
@author John Smith | Describes an author. | Class, Interface, Enum | |
{@docRoot} | Represents the relative path to the generated document's root directory from any generated page. | Class, Interface, Enum, Field, Method | |
@version version | Provides software version information. | Module, Package, Class, Interface, Enum | |
@since since-text | Describes when this functionality has first existed. | Class, Interface, Enum, Field, Method | |
@see reference | Provides a link to other element of documentation. | Class, Interface, Enum, Field, Method | |
@param name description | Describes a method parameter. | Method | |
@return description | Describes the return value. | Method | |
@exception classname description @throws classname description |
Describes an exception that may be thrown from this method. | Method | |
@deprecated description | Describes an outdated method. | Class, Interface, Enum, Field, Method | |
{@inheritDoc} | Copies the description from the overridden method. | Overriding Method | 1.4.0 |
{@link reference} | Link to other symbol. | Class, Interface, Enum, Field, Method | |
{@linkplain reference} | Identical to {@link}, except the link's label is displayed in plain text than code font. | Class, Interface, Enum, Field, Method | |
{@value #STATIC_FIELD} | Return the value of a static field. | Static Field | 1.4.0 |
{@code literal} | Formats literal text in the code font. It is equivalent to <code>{@literal}</code>. | Class, Interface, Enum, Field, Method | 1.5.0 |
{@literal literal} | Denotes literal text. The enclosed text is interpreted as not containing HTML markup or nested javadoc tags. | Class, Interface, Enum, Field, Method | 1.5.0 |
{@serial literal} | Used in the doc comment for a default serializable field. | Field | |
{@serialData literal} | Documents the data written by the writeObject( ) or writeExternal( ) methods. | Field, Method | |
{@serialField literal} | Documents an ObjectStreamField component. | Field |
An example of Javadoc to document a method follows. Notice that spacing and number of characters in this example are as conventions state[clarification needed].
/**
* Validates a chess move.
*
* <p>Use {@link #doMove(int fromFile, int fromRank, int toFile, int toRank)} to move a piece.
*
* @param fromFile file from which a piece is being moved
* @param fromRank rank from which a piece is being moved
* @param toFile file to which a piece is being moved
* @param toRank rank to which a piece is being moved
* @return true if the move is valid, otherwise false
* @since 1.0
*/
boolean isValidMove(int fromFile,Javadoc Tutorials: Javadoc is an extensible documentation generation system which reads specially formatted comments in Java source code and generates compiled documentation. It is typically used to produce API documentation in the form of HTML web pages.
Latest online Javadoc Tutorials with example so this page for both freshers and experienced candidate who want to get job in Javadoc company