# JAVA - Comments

Advertisements

The Comments are added in programming code with the purpose of making the code easier to understand. It makes the code more readable and hence easier to update the code later. Comments are ignored by compiler while running the code. In Java, there are two ways of putting a comment.

• Single line comment
• Block comment

## Single line Comment:

It starts with // and ends with the end of that line. Anything after // to the end of line is a single line comment and will be ignored by compiler.

### Syntax

//single line comment.
statements; //single line comment.


### Example:

public class MyClass {
public static void main(String[] args) {
//first single line comment.
System.out.println("Hello World!."); //second single line comment.
}
}


Output

Hello World!.


## Block Comment:

It starts with /* and ends with */. Anything between /* and */ is block comment and will be ignored by compiler.

### Syntax

/*block
comment.*/
statements; /*block comment.*/ statements;


### Example:

public class MyClass {
public static void main(String[] args) {
/*first
block comment. */
System.out.println(/*second block comment.*/"Hello World!.");
}
}


Output

Hello World!.