Content deleted Content added
Tags: Mobile edit Mobile web edit |
|||
(45 intermediate revisions by 22 users not shown) | |||
Line 1:
{{short description|Documentation generator for Java}}
{{
The
Javadoc
Although some criticize Javadoc and API document generators in general, one motivation for creating Javadoc was that more traditional (less automated) API documentation is often out-of-date or does not exist due to business constraints such as limited availability of [[API writer|technical writers]].<ref>{{cite web|url=http://www.artima.com/intv/jackpot3.html
|title=Visualizing with JavaDoc
|first1=Bill| last1=Venners| first2=James| last2=Gosling | display-authors=etal | publisher=artima.com
|date=2003-07-08
|access-date=2013-01-19
|quote=When I did the original JavaDoc in the original compiler, even the people close around me pretty soundly criticized it. And it was interesting, because the usual criticism was: a good tech writer could do a lot better job than the JavaDoc does. And the answer is, well, yeah, but how many APIs are actually documented by good tech writers? And how many of them actually update their documentation often enough to be useful?}}</ref>
Javadoc has been
Javadoc and the source code comments used by Javadoc, do not affect the performance of a Java executable since comments are ignored by the compiler.
==
Javadoc ignores comments unless they are specially marked. A Javadoc comment is marked with an extra asterisk after the start of a multi-line comment: <code>/**</code>. A comment block pertains to the symbol that follows the block.
An example of a class header block follows:
<syntaxhighlight lang="java">
/**
* Provides some service
* @author Jill Smith <address@example.com>
* @version 1.6
* @since 1.2
*/
public class Test {}
</syntaxhighlight>
For a method, the first line is a short description of the method. If more detail is warranted, then it may be followed by a longer description in additional paragraphs. Following that are optionally various tags.
Various aspects of HTML as supported via Javadoc. For example <code><p></code> denotes a paragraph break.
An example of a method header block follows:
<syntaxhighlight lang="java">
/**
*
* <p>
* Longer description. If there were any, it would be
* <p>
* And even more
* paragraphs separated by
*
* @param
* @return Description
*/
public int methodName
</syntaxhighlight>
Variables
<syntaxhighlight lang="java">
/**
* Description of the variable here
*/
private int debug = 0;
</syntaxhighlight>
A more complete example follows:
<syntaxhighlight lang="java">
/**
* 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, int fromRank, int toFile, int toRank) { ... }
/**
* Moves a chess piece
*
* @see java.math.RoundingMode
*/
void doMove(int fromFile, int fromRank, int toFile, int toRank) { ... }
</syntaxhighlight>
== Markdown ==
From Java 23 onwards, Javadoc supports the [[Markdown]] standard CommonMark on comment lines that start with <code>///</code> instead of the older multiline format.<ref>https://openjdk.org/jeps/467 {{Bare URL inline|date=August 2025}}</ref>
== Doclets ==
A Doclet program works with Javadoc to select which content to include in the documentation, format the presentation of the content and create the file that contains the documentation.<ref>{{cite web | url=https://docs.oracle.com/javase/8/docs/technotes/guides/javadoc/doclet/overview.html | title=Doclet Overview }}</ref> A Doclet is written in Java and uses the {{Javadoc:SE|jdk/javadoc/doclet|name=Doclet API|module=jdk.javadoc}},
The {{Javadoc:SE|jdk/javadoc/doclet|StandardDoclet|module=jdk.javadoc}}[https://docs.oracle.com/javase/9/javadoc/javadoc-command.htm#JSJAV-GUID-04BFA924-7C45-4E9C-91D1-0B77D97E65AB] included with Javadoc generates [[API]] documentation as frame-based [[HTML]] files. Other Doclets are available on the web {{Citation needed|reason=Is this still true today?|date=December 2017}}, often for free. These can be used to:
* Create other types of documentation (non-API)
* Output to a format other than HTML; such as [[PDF]]
* Output as HTML with additional features such as a search or with embedded [[Unified Modeling Language|UML]] diagrams generated from the Java classes
== Tags ==
{{Update|section|inaccurate=yes|reason=Should be updated according to the [https://docs.oracle.com/en/java/javase/21/docs/specs/javadoc/doc-comment-spec.html official documentation]|date=November 2023}}
Some of the available Javadoc tags<ref>[https://docs.oracle.com/en/java/javase/13/docs/specs/javadoc/doc-comment-spec.html JavaSE 13 Documentation Comment Specification]</ref> are listed in the table below:
{| class="wikitable"
!Syntax
!Usage
!Applies to
!Since
|-
|'''@author''' ''
|-
|{'''@docRoot'''}
|Represents the relative path to the generated document's root directory from any generated page
|Class, Interface, Enum, Field, Method
|
|-
|'''@version''' ''version''||
|-
|'''@since''' ''since-text''|| Describes when this functionality
|-
|'''@see''' ''reference''||
|-
|'''@param''' ''name description''|| Describes a method parameter
|-
|'''@return''' ''description''|| Describes the return value
|-
|'''@exception''' ''classname description''<br />'''@throws''' ''classname description''|| Describes an exception that may be thrown from this method
|-
|'''@deprecated''' ''description''||
|-
|{'''@inheritDoc'''}||Copies the description from the overridden method
|-
|{'''@link''' ''<var>reference</var>''}||Link to other symbol
|-
|{'''@linkplain''' ''<var>reference</var>''}
|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
|-
|{'''@code''' ''literal''}|| Formats literal text in the code font
|-
|{'''@literal''' ''literal''}|| Denotes literal text
|-
|{'''@serial''' ''literal''}
|
|Field
|
|-
|{'''@serialData''' ''literal''}
|
|Field, Method
|
|-
|{'''@serialField''' ''literal''}
|
|Field
|
|}
== See also ==
* [[Comparison of documentation generators]]
* [[Doxygen]]
* [[.NET documentation comments|.NET XML documentation comments]]
== References ==
Line 215 ⟶ 174:
* [https://www.jcp.org/en/jsr/detail?id=260 JSR 260] Javadoc Tag Technology Update [[Java Specification Request]] (defines new Javadoc tags)
* [https://web.archive.org/web/20130927133806/https://today.java.net/pub/a/today/2004/08/26/ashkelon.html Improve on Javadoc with ashkelon]
* [https://javadoc.allimant.org/ Various Java documentations converted to Windows Help format]
[[Category:Free documentation generators]]
[[Category:Source code documentation formats]]
[[Category:Java development tools]]
|