Java comments in Code

Home arrow Java Tutorials arrow Getting Started arrow Java comments in Code
Java comments in Code Print E-mail
Contributed by Joe   
Monday, 03 July 2006

Java comments in Code

There are three styles of java comments.

Comments enable you to write descriptive text alongside your code, annotating it for programmers who may read your code in the future. That programmer may well be you months or years later. You save yourself effort by commenting your own code. Also, you often find bugs when you write comments, because explaining what the code is supposed to do forces you to think about it.

Text that occurs between /* and */ is ignored by the compiler. This style of comment can be used on part of a line, a whole line, or more commonly (as in the example) to define a multiline comment. For single line and part line comments you can use // which tells the compiler to ignore everything after it on that line.

The third kind of comment appears at the very top, between /** and */. A comment starting with two asterisks is a documentation comment ("doc comment" for short). Documentation comments are intended to describe declarations that follow them. The comment in the previous example is for the main method. These comments can be extracted by a tool that uses them to generate reference documentation for your classes. By convention, lines within a documentation comment or a /*...*/ comment have a leading asterisk (which is ignored by documentation tools), which gives a visual clue to readers of the extent of the comment.

 Below is an java Comments example which has three kinds of comments:

/* text */
The compiler ignores everything from /* to */.
/** documentation */
This indicates a documentation comment (doc comment, for short). The compiler ignores this kind of comment, just like it ignores comments that use /* and */. The JDK javadoc tool uses doc comments when preparing automatically generated documentation. For more information on javadoc, see the Javadoc tool documentation .
// text
The compiler ignores everything from // to the end of the line.

 

Last Updated ( Monday, 03 July 2006 )

  home              contact us

 

©2006-2012 DeveloperZone.biz   All rights reserved     powered by Mambo Designed by Siteground