What's the difference between
/**
* comment
*
*
*/
and
/*
*
* comment
*
*/
in Java? When should I use them?
What's the difference between
/**
* comment
*
*
*/
and
/*
*
* comment
*
*/
in Java? When should I use them?
The first is Javadoc comments. They can be processed by the
javadoc
tool to generate the API documentation for your classes. The second is a normal block comment.Java supports two types of comments:
/* multiline comment */
: The compiler ignores everything from/*
to*/
. The comment can span over multiple lines.// single line
: The compiler ignores everything from//
to the end of the line.Some tool such as javadoc use a special multiline comment for their purpose. For example
/** doc comment */
is a documentation comment used by javadoc when preparing the automatically generated documentation, but for Java it's a simple multiline comment.Reading the section 3.7 of JLS well explain all you need to know about comments in Java.
About your question,
The first one
is used to declare Javadoc Technology.
For more information on
Doclet
refer to the API.The second one, as explained clearly in JLS, will ignore all the text between
/*
and*/
thus is used to create multiline comments.Some other things you might want to know about comments in Java
/* and */
have no special meaning in comments that begin with//
.//
has no special meaning in comments that begin with/* or /**
.Thus, the following text is a single complete comment: