What\'s the difference between
/**
* comment
*
*
*/
and
/*
*
* comment
*
*/
in Java? When shou
Comments in the following listing of Java Code are the greyed out characters:
/**
* The HelloWorldApp class implements an application that
* simply displays "Hello World!" to the standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); //Display the string.
}
}
The Java language supports three kinds of comments:
/* text */
The compiler ignores everything from /* to */.
/** documentation */
This indicates a documentation comment (doc comment, for short). The compiler ignores this kind of comment, just like it ignores comments that use /* and */. The JDK javadoc tool uses doc comments when preparing automatically generated documentation.
// text
The compiler ignores everything from // to the end of the line.
Now regarding when you should be using them:
Use // text when you want to comment a single line of code.
Use /* text */ when you want to comment multiple lines of code.
Use /** documentation */ when you would want to add some info about the program that can be used for automatic generation of program documentation.