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?
There is no difference. It comes down to user preference. However, special variations on those syntaxes are interpreted by Javadoc for generating documentation.
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.
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 ( // ... ).
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).
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With