Important Java Concept

Comments in Java


Comments are basically lines that give us a brief description of the code written without getting interpreted by the compiler.


Let’s create a Comment in Java


A comment begins with 2 forward slashes. Let’s see an example to understand it better.

// This is a comment


Types of Comments


Comments can basically be submerged into the following types:

1. Single Line Comments
2. Multi Line Comments


Single Line Comments


The Single Line Comment is the easiest type of comment. It starts with 2 forward slashes and is further followed by an explanation.
It is used for some quick explanation of the code.

// This program prints Hi



Multi Line Comments


A comment spread over multiple lines is called a multi line comment. Let’s go over the following example to understand multi line comments.

This program prints the sum of 2 variables
here a is 1 and b is 2
so c will be 3
int a = 1;
int b = 2;
int c = a + b;



Do you want

Java Tutor?

Aniket Malik

Aniket Malik


🟢 Oracle Certified Java Expert

🟢 300 + ⭐ ⭐ ⭐ ⭐ ⭐

🟢 & in CSE

🟢 6+ Years of Teaching Experience

🟢 Worked as SE in Virtusa and Digidez

Do you want

Java Tutor?