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