Javadoc - Geisonszo/TecProg-Emergo GitHub Wiki
7. Javadoc
7.1 Formatting
7.1.1 General form
The basic formatting of Javadoc blocks is as seen in this example:
/**
* Multiple lines of Javadoc text are written here,
* wrapped normally...
*/
public int method(String p1) { ... }
... or in this single-line example:
/** An especially short bit of Javadoc. */
The basic form is always acceptable. The single-line form may be substituted when there are no at-clauses present, and the entirety of the Javadoc block (including comment markers) can fit on a single line.
7.1.2 Paragraphs
One blank line—that is, a line containing only the aligned leading asterisk (*
)—appears between paragraphs, and before the group of "at-clauses" if present. Each paragraph but the first has <p>
immediately before the first word, with no space after.
7.1.3 At-clauses
Any of the standard "at-clauses" that are used appear in the order @param
, @return
, @throws
, @deprecated
, and these four types never appear with an empty description. When an at-clause doesn't fit on a single line, continuation lines are indented four (or more) spaces from the position of the @
.
The summary fragment
The Javadoc for each class and member begins with a brief summary fragment. This fragment is very important: it is the only part of the text that appears in certain contexts such as class and method indexes.
This is a fragment—a noun phrase or verb phrase, not a complete sentence. It does not begin with A {@code Foo} is a...
, or This method returns...
, nor does it form a complete imperative sentence like Save the record.
. However, the fragment is capitalized and punctuated as if it were a complete sentence.
Tip: A common mistake is to write simple Javadoc in the form /** @return the customer ID */. This is incorrect, and should be changed to /** Returns the customer ID. */.
7.3 Where Javadoc is used
At the minimum, Javadoc is present for every public
class, and every public
or protected
member of such a class, with a few exceptions noted below.
Additional Javadoc content may also be present, as explained in Section 7.3.4, Non-required Javadoc.
7.3.1 Exception: self-explanatory methods
Javadoc is optional for "simple, obvious" methods like getFoo
, in cases where there really and truly is nothing else worthwhile to say but "Returns the foo".
Important: it is not appropriate to cite this exception to justify omitting relevant information that a typical reader might need to know. For example, for a method named getCanonicalName, don't omit its documentation (with the rationale that it would say only /** Returns the canonical name. */) if a typical reader may have no idea what the term "canonical name" means!
7.3.2 Exception: overrides
Javadoc is not always present on a method that overrides a supertype method.
7.3.4 Non-required Javadoc
Other classes and members have Javadoc as needed or desired.
Whenever an implementation comment would be used to define the overall purpose or behavior of a class or member, that comment is written as Javadoc instead (using /**
).
Non-required Javadoc is not strictly required to follow the formatting rules of Sections 7.1.2, 7.1.3, and 7.2, though it is of course recommended.