7.1.2. Comments
Comments within source code exist for the convenience of human programmers. They play no part in the
generation of code and so are ignored during scanning. There are three kinds of comments:
// comment. Characters from // to the end of the line are ignored
/* comment
*/
All characters between /* and the next */ are ignored.
/** comment
*/
All characters between /** and the next */ are ignored.
These documentation comments come immediately before identifier declarations and are
included in automatically generated documentation. These comments are described in
Chapter 19.
Comments can include any valid Unicode character, such as yin-yang (\u262f), asterism (\u2042),
interrobang (\u203d), won (\u20a9), scruple (\u2108), or a snowman (\u2603).[3]
[3] These characters are , , , , , and , respectively.
Comments do not nest. This following tempting code does not compile:
/ Comment this out for now: not implemented
/ Do some really neat stuff /
universe.neatStuff();
/
The first / starts a comment; the very next / ends it, leaving the code that follows to be parsed; and the
invalid, stand-alone */ is a syntax error. The best way to remove blocks of code from programs is either to
put a // at the beginning of each line or use if(false) like this:
if (false) {
// invoke this method when it works
dwim();
}
This technique requires that the code to be removed is complete enough to compile without error. In this case
we assume that the dwim method is defined somewhere.
7.1.3. Tokens
The tokens of a language are its basic words. A parser breaks source code into tokens and then tries to figure
out which statements, identifiers, and so forth make up the code. Whitespace (spaces, tabs, newlines, and form
feeds) is not significant except to separate tokens or as the contents of character or string literals. You can take
any valid code and replace any amount of intertoken whitespace (whitespace outside strings and characters)
with a different amount of whitespace (but not none) without changing the meaning of the program.
Whitespace must be used to separate tokens that would otherwise constitute a single token. For example, in
the statement