Java Comments

 

Java Comments

Comments in any programming language are ignored by the compiler or the interpreter. A comment is a part of the coding file that the programmer does not want to execute, rather the programmer uses it to either explain a block of code or to avoid the execution of a specific part of code while testing.


There are two types of coments:


  • Single-line comment
  • Multi-line comment

 

A. Single Line Comments:

To write a single-line comment just add a ‘//’ at the start of the line.


Example:

package syntax1;
public class Details {
    public static void main(String[] args) {
        //This is a single line comment
        System.out.println("Hello World!!!");
      }
}


Output:

Hello World!!!

 

B. Multi Line Comments:

To write a multi-line comment just add a ‘/*…….*/’ at the start of the line.


Example:

package syntax1;

public class Details {
    public static void main(String[] args) {
        /*This
         * is 
         * a
         * Multiline 
         * Comment
         */
        System.out.println("Hello World!!!");
      }
}

 

Output:

Hello World!!!