-2

I always use the comment operator in Java whenever I need to take some note or explain the function.

/*
 * Comment
 */

I also saw someone use the comment operator like this

/**
 * Comment.
 */

Interestingly, if you use this comment operator, it will display @param if you have parameter and @return if you have a return.

He said to me that I need to put a period at the end of the sentence; then, if you use the function somewhere else, you can view the comment as a documentation, like Javadoc.

I did not know how to view the comment as a documentation. Can you show me how to display it in both Netbean and Eclipse. Thanks !

  • 1
    This is called [Javadoc](http://www.oracle.com/technetwork/articles/java/index-jsp-135444.html). That should help you find the information you're looking for. – Kevin Krumwiede Jul 19 '15 at 22:13
  • In Eclipse, you can use Window->Show View->Javadoc and set the cursor to any function, variable etc. and you will see its javadoc. Good for both checking your own JavaDoc and reading third party documentation – Daniel Alder Jul 19 '15 at 22:20

2 Answers2

1

Your colleague was right: that's a Javadoc comment. You can use the Javadoc tool directly to turn it into HTML (which you can then open with your browser), or ask your IDE to do it for you:

Wander Nauta
  • 18,832
  • 1
  • 45
  • 62
0

Yes, this is use to document function or classes.

/**
* This function is used to add integer a to integer b.
*
* @param this first integer.
* @param b the second integer
* @return the addition of a and b
*/
public int add(int a, int b) {
    return a + b;
}

if somewhere else in your code you call this function you'll be able to see the comment. (event with editor auto complete).

Anthony Raymond
  • 7,434
  • 6
  • 42
  • 59