Comments
Java supports both C-style block comments
delimited by /* and */ and C++
- style line comments indicated by //:
/* This is a
multiline
comment. */
// This is a single-line comment
// and so // is this
As
in C, block comments can’t be nested.
Single-line comments are delimited by the end of a
line; extra // indicators inside a single line
have no effect. Line comments are useful for short comments within
methods; they don’t conflict with wrapping block comment
indicators around large chunks of code during development.
Javadoc Comments
By convention,
a block comment beginning with
/** indicates a special doc
comment
. A doc comment is designed to be
extracted by automated documentation generators,
such as the DSK’s javadoc program. A doc
comment is terminated by the next */, just as with
a regular block comment. Leading spacing up to a *
on each line is ignored; lines beginning with @
are interpreted as special tags for the documentation generator.
Here’s an example:
/** * I think this class is possibly the most amazing thing you will * ever see. Let me tell you about my own personal vision and * motivation in creating it. * <p> * It all began when I was a small child, growing up on the * streets of Idaho. Potatoes were the rage, and life was good... * * @see PotatoPeeler * @see PotatoMasher * @author John 'Spuds' Smith * @version 1.00, 19 Dec 1996 */
javadoc creates HTML format documentation of classes by reading the source code and the embedded comments. The author and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access