|
Do you need help with your Java programming?
Click here for instant help with your Java code. |
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! | |
Search for code examples on this site
