Comments in general : Comments « Language « Java Tutorial

It is good practice to write comments explaining your code.

There are two types of comments in Java, both with syntax similar to comments in C and C++.

  1. Traditional comments: Enclose a traditional comment in /* and */.
  2. End-of-line comments: Use double slashes (//) which causes the rest of the line ignored by the compiler.

Traditional comments do not nest, which means

  /* comment 1 */
  comment 2 */
  1. is invalid because the first */ after the first /* will terminate
  2. which will generate a compiler error

End-of-line comments can contain anything, including the sequences of characters /* and */, such as this:

// /* this comment is okay */

1.4.1.Comments in general
1.4.2.Program Comments: Single line of comment
1.4.3.Multiple lines of comment