Comments in Java

In a program, comments take part in making the program become more human readable by placing the detail of code involved and proper use of comments makes maintenance easier and finding bugs easily. Comments are ignored by the compiler while compiling a code.


In Java there are three types of comments:


    1. Single – line comments
    The single line comment is used to comment only one line.

    Syntax: //This is single line comment

    2. Multi – line comments
    The multi line comment is used to comment multiple lines of code.

      Syntax:
      /*
      This
      is
      multi line
      comment
      */


    3. Documentation comments
    This type of comments are used generally when writing code for a project/software package, since it helps to generate a documentation page for reference, which can be used for getting information about methods present, its parameters, etc.

      Syntax:
      /**
      This
      is
      documentation
      comment
      */
    Example: