Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between comments /* */ and /** */? [duplicate]

Tags:

java

eclipse

What is the difference between the below comments in eclipse:

  1. / followed by one *

    /* comments... */

  2. / followed by two **

    /** comments... */

The color of the both comments are also different. And when we use the 2nd type comment it will automatically displays the @author name. Why its like this?

like image 790
Praveen P Moolekandathil Avatar asked Apr 13 '26 11:04

Praveen P Moolekandathil


1 Answers

The /** */ comments are javadoc comments, more details here:

Documentation comments (doc comments)

The special comments in the Java source code that are delimited by the /** ... */ delimiters. These comments are processed by the Javadoc tool to generate the API docs.

Their specific formatting lets some tools build the API documentation like the one you see of the standard package but also, if you run it, of your own code. It lets you describe in a formal way the arguments, what is returned, etc.

Not only is this documentation presented to you when you generate it (as HTML or in another format), it's also presented in IDE like Eclipse in multiple ways, for example when your mouse hovers some names. It's an important good practice to write in javadoc the important information needed by the users of your methods and class (and no more than what's useful).


It's good to mention that /* */ is useful not only for commenting-out multiple lines. Consider a situation when you want to comment-out something inside an if condition:

if(a==b && c == d)

Then if you want to remove a==b and put it back later on, you can't use // because it'll comment-out the whole line after it, so you do:

if(/*a==b &&*/ c == d)

By the way, this has nothing to do with Eclipse, that's a Java feature.

like image 170
6 revs, 2 users 59%Maroun Maroun Avatar answered Apr 14 '26 23:04

6 revs, 2 users 59%Maroun Maroun