Comments
Java supports both C-style block
comments delimited by /* and */ and C++-style
line comments indicated by //:
/* This is amultilinecomment. */// This is a single-line comment// and so // is this
Block comments have both a beginning and end sequence and can cover
large ranges of text. However, they cannot be “nested,” meaning that you
can’t have a block comment inside of a block comment without the compiler
getting confused. Single-line comments have only a start sequence and 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 block comments, so you can still comment out larger
chunks of code in which they are nested.
Javadoc Comments
A block comment beginning with /** indicates a special
doccomment. A
doc comment is designed to be extracted by automated documentation
generators, such as the JDK’s javadoc program. A
doc comment is terminated by the next */, just as with a regular block comment.
Within the doc comment, lines beginning with @ are interpreted as
special instructions for the documentation generator, giving it
information about the source code. By convention, each line of a doc
comment begins with a *, as shown in
the following example, but this is optional. Any leading spacing and the
* on each line are ignored:
/*** I think this class is possibly the most amazing thing you will* ever see. Let me tell you about my own personal ...
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