Comments:

Comments are used to explain your code and they have nothing to do with the compiler. Compiler ignores your comment and do not consider them the part of your code. They just make your code more readable.

There are two types of comments:

  • Single Lined Comments
  • Multi Lined Comments

Single Lined Comments:

Put two forward slashes before a line.

comment.java
public class Main {
    public static void main(String[] args) {
        // I am printing Hello World
        System.out.println("Hello World");
    }
}

Multi Lined Comments:

Put /* at the start and */ at the end.

comment.java
public class Main {
    public static void main(String[] args) {
        /* I am printing Hello World
        and this is a comment */
        System.out.println("Hello World");
    }
}

Note:

  • If you do not want some lines of your code to execute, put them in comments.
  • To comment a line, click on that line to place cursor on that line and then press "Ctrl + /".
  • Comments are just used to increase the readability of your code.