farshad farshad - 2 years ago 452
Java Question

Java: comments /* * * */

Quick question, it there a difference between:

/* This is first line of comments
This is the second line
And this will be the last line
*/


and:

/*This is first line of comments
*This is the second line
*And this will be the last line
*/


in java language?

The source I learned from teaches the second form, but I found out the fist one works too.

Answer Source

There is no difference at all as far as the compiler is concerned. It's just a matter of what looks pretty and what documentation generators rely upon. That last point is surprisingly important: particularly in Java. (Javadoc relies upon well-defined comment forms.) /* defines the start of a comment, and you'll stay in "comment mode" until the first */ is reached.

So further /* are allowed within a comment block (but they don't nest so you still only need one closing */). And the single line comment // within a comment block is benign: //*/ will close a comment block.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download