/** and /* in Java Comments -


what's difference between

/**  * comment  *  *  */ 

and

/*  *   * comment  *  */ 

in java? when should use them?

the first form called javadoc. use when you're writing formal apis code, generated javadoc tool. example, the java 7 api page uses javadoc , generated tool.

some common elements you'd see in javadoc include:

  • @param: used indicate parameters being passed method, , value they're expected have

  • @return: used indicate result method going give back

  • @throws: used indicate method throws exception or error in case of input

  • @since: used indicate earliest java version class or function available in

as example, here's javadoc compare method of integer:

/**  * compares 2 {@code int} values numerically.  * value returned identical returned by:  * <pre>  *    integer.valueof(x).compareto(integer.valueof(y))  * </pre>  *  * @param  x first {@code int} compare  * @param  y second {@code int} compare  * @return value {@code 0} if {@code x == y};  *         value less {@code 0} if {@code x < y}; ,  *         value greater {@code 0} if {@code x > y}  * @since 1.7  */ public static int compare(int x, int y) {     return (x < y) ? -1 : ((x == y) ? 0 : 1); } 

the second form block (multi-line) comment. use if want have multiple lines in comment.

i you'd want use latter form sparingly; is, don't want overburden code block comments don't describe behaviors method/complex function supposed have.

since javadoc more descriptive of two, , can generate actual documentation result of using it, using javadoc more preferable simple block comments.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -