Java Comments

Every programming language’s compiler and interpreter ignores comments. This includes Java. A comment is a section of code that the programmer does not wish to run; instead, they use them to either explain a block of code or to prevent a particular section from running when testing.

There are two types of comments in Java:

  • single-line
  • multi-line

Single-line comment:

Simply add a “//” at the beginning of a line to start a remark.

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!!!

Multi-line comment:

Simply add a “/*…….*/” at the beginning of each line to create a multi-line comment.

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!!!
Shubhajna Rai
Shubhajna Rai

A Civil Engineering Graduate interested to share valuable information with the aspirants.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in