A comment in Java programming is a statement that is not executed when the program is run. The only purpose of the comment is to be read by someone who is looking at the code.
Comments can be used to:
Java supports several ways of commenting:
The single line comment is used to comment single line of code.
Syntax
//This is single line comment
public class CommentExample {
public static void main(String[] args) {
int a=10;//Here, a is a variable
System.out.println(i);
}
}
The multi line comment is used to comment multi line of code.
Syntax
/*
This
is
multi line
comment
*/
public class CommentExample2 {
public static void main(String[] args) {
int a=10;
int b=20;
int c=30;
System.out.println(a);
/*System.out.println(b);
System.out.println(b); */
}
}
Documentation Comment
The java documentation comment is used to create a document for the project or code.
**
* The HelloWorld program implements an application that
* simply displays "Hello World!" to the standard output.
*
* @author James Gosling
* @version 1.0
* @since 2014-03-31
*/
public class HelloWorld {
public static void main(String[] args) {
/* Prints Hello, World! on standard output.
System.out.println("Hello World!");
}
}
The javadoc tool recognizes only this type of comment.