Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between /* and /**

Tags:

java

eclipse

I found, in eclipse,

/*
 * Hello world, this is green.
 *
 */

The comments will be green. However,

/**
 * Hello moon, this is blue.
 *
 */

If I use /**, it will become blue. So why? Any difference?

like image 449
Gonghan Avatar asked Apr 29 '14 07:04

Gonghan


People also ask

What is the difference between single line comment and multi line comment?

There is no difference. It comes down to user preference. However, special variations on those syntaxes are interpreted by Javadoc for generating documentation.

What is the difference between Javadoc and comments?

Whereas inline and block Java comments are read by other developers who maintain the code, JavaDoc comments are for developers who use your code. You can only place JavaDoc comments before the class declaration or a method declaration. Also, they describe the purpose of the class or method and how it might be used.

What are the differences of Java comments?

For the Java programming language, there is no difference between the two. Java has two types of comments: traditional comments ( /* ... */ ) and end-of-line comments ( // ... ).

How do you comment a paragraph in Java?

Single-line comments start with two forward slashes ( // ). Any text between // and the end of the line is ignored by Java (will not be executed).


1 Answers

While /* starts a regular multi-line comment, /** starts a multi-line comment supporting the javadoc tool, which generates HTML documentation from your comments.

This is an example from the documentation:

/**
 * Returns an Image object that can then be painted on the screen. 
 * The url argument must specify an absolute {@link URL}. The name
 * argument is a specifier that is relative to the url argument. 
 * <p>
 * This method always returns immediately, whether or not the 
 * image exists. When this applet attempts to draw the image on
 * the screen, the data will be loaded. The graphics primitives 
 * that draw the image will incrementally paint on the screen. 
 *
 * @param  url  an absolute URL giving the base location of the image
 * @param  name the location of the image, relative to the url argument
 * @return      the image at the specified URL
 * @see         Image
 */
public Image getImage(URL url, String name) {
    try {
        return getImage(new URL(url, name));
    } catch (MalformedURLException e) {
        return null;
    }
}

The Java API specification itself is an example of HTML documentation generated through javadoc.

like image 131
jnovo Avatar answered Nov 04 '22 03:11

jnovo