What are Java comments?
Comments are used to explain the code and make it more readable. They are not executed by the compiler. There are two types of comments in Java: single-line comments and multi-line comments.
Single-line comments :-
Single-line comments start with two forward slashes (//) and continue to the end of the line.
For example :-
// This is a single-line comment
Multi-line comments :-
Multi-line comments start with a forward slash and asterisks (/*) and end with asterisks and a forward slash (*/).
For example :-
/*
This is a multi-line comment
that can span multiple lines
*/
Example :-
//Hare I use Single line comments and Multi line comments.
class Scomment
{
public static void main(String args[])
{
/* In this program I use Single line comments
and Multi line comments */
System.out.println(“Multi line comments below”);
}
}
Note :- I use Comments that is not read as the code but it is read as comments in the program by java compiler
Why use Java comments?
There are several reasons why you should use Java comments:
How to write good Java comments?
Here are some tips for writing good Java comments:
=> I hope this explanation of Java comments is helpful.