Comments

Purpose:

To describe in natural language what the code is doing.

Mechanics:

/* This is a comment. */
// This is also a comment.
/** This is a comment which will appear in the auto-generated documentation. */

Usage:

  • Anything between /* */ or /** */ or following // is ignored by the Java compiler.
  • Comments are crucial:
    1. At the top of the program. This program header comment should contain:
      • the program name
      • your name
      • the date of the last revision
      • a description of the program: its major structure and breakdown
    2. At the top of each method. This method header comment should contain:
      • the class name and the method name
      • the purpose of the method
      • any complex or interesting points about the method, such as error conditions or special cases that may or may not be handled by the method.
    3. In the definition of a class or variable of any sort.

Restrictions:

Comments cannot be nested
Back to the Table of Contents
email suggestions to: cs015tas@cs.brown.edu