Comments in the Java code


Comments in Java code is intended for human readers as well as generating documentation of the code.
There are three types of comments you can make in the code:


Single-line comment


The single line comment starts with two slashes and that indicates that the rest of the current line is commented out.


String name = "John"; // Initialize the String variable name


Multiple-line comment


Multi-line comments starts with the characters /* and ends with the characters */.
Any text placed between the start and the end is ignored by the compiler regardless of how many rows that are commented out.
For example:


/*
 * Adding a multiline comment.
 * Often the * character is used on every row to format the block of comments although it's not mandatory.
 */



This type of comment can of course also be used when commenting a single line:


/* Commenting only a single line */


Doc comment


The third type is a variation of the previous. It is used to comment for example methods to be used by the doc generator (javadoc) when auto generating API documentation in HTML format.


/**
 * This method saves data to database.
 *
 * @param connection The database connection.
 * @param data The data to be saved.
 *
 * @return <tt>true</tt> on successful operation,
 * <tt>false</tt> on error saving to database.
 * @author javadb.com
 */

public boolean saveToDb(Connection connection, Hashtable data) {

  //method body goes here...

Previous     Next

Tutorial Home


Do you know your Java?
Take a Ten-Question-Java-Quiz!

Bookmark and Share




Need help with your Java code? It's secure and confidential.
This is how it works:
Send a detailed description of what you need help with, the more details the better. Also provide a deadline for when it has to be finished. More time means better chance of putting your request into the schedule.

If the request is serious you will shortly receive an email with the price, to which you have to respond if you accept.

Once you have accepted, the work will begin on developing your code by an experienced Java developer. When the code is finished a link to a secure payment will be sent to you.

The source code is then sent to you once the payment is completed.

IMPORTANT! The request needs to be very detailed, else it may be ignored.


Write your detailed request here:

E-mail address: