by Dinesh Thakur Category: Java Language

Comments are usually non executable statements which are meant for the programmers own convenience. A comment is usually explanation regarding the statement.  
Programmers use comments to allow readers of their code to better understand the code and how it works. Comments consist of English phrases that describe the purpose of the program, the use of identifiers, and the purpose of each program step.

Comments in Java are specified in one of three ways. The first two formats are borrowed directly from C++ and C. Comments in Java, as in C++ and C, do not end up in the executable bytecode. For this reason, comments can be used as often as deemed necessary, without the worry of inflated code.

There are three types of comments in java. They are:

Single line (or end-of line) comment

Single line comment allows only one line. It starts with a double slash symbol (//) and terminates at the end of the current line. The compiler ignores everything from // to the end of the line. For example:
// Calculate sum of two numbers

Multi line comment

If the comment exceeds more than one line, multiline comment is used. Java programmer can use C/C++ comment style that begins with delimiter /* and ends with */. All the text written between the delimiter is ignored by the compiler. This style of comments can be used on part of a line, a whole line or more commonly to define multi-line comment. For example.
/* Calculate
sum of two numbers */

Documentation comment

Documentation comment is used to generate document automatically. This comment style is new in Java. Such comments begin with delimiter /** and end with */ . The compiler also ignores this type of comments just like it ignores comments that use /* and */.The main purpose of this type of comment is to automatically generate program documentation. The javadoc tool reads these comments and uses them to prepare your program's documentation in HTML format. For example. /**The text enclosed here will be part of program documentation */.



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.