Types of Comments in Java
Types of Comments in Java
Types of Comments in Java
In this tutorial, you will learn about Java comments, why we use them, and
how to use comments in right way.
single-line comment
multi-line comment
Single-line Comment
A single-line comment starts and ends in the same line. To write a single-
line comment, we can use the // symbol. For example,
class Main {
public static void main(String[] args) {
{
// prints "Hello, World!"
System.out.println("Hello, World!");
}
}
Output:
Hello, World!
The Java compiler ignores everything from // to the end of line. Hence, it is
also known as End of Line comment.
Multi-line Comment
When we want to write comments in multiple lines, we can use the multi-
line comment. To write multi-line comments, we can use the /*....*/ symbol.
For example,
Output:
Hello, World!