Wednesday, August 17, 2016

Java Comments

Java Comments

Comments

The purpose of including comments in your code is to explain what the code is doing. Java supports both single and multi-line comments. All characters that appear within a comment are ignored by the java compiler.



Single-line comment

A single-line comment starts with two forward slashes and continues until it reaches the end of the line.
For example:

// this is a single-line comment
X= 5; //Assign 5 to Variable X

Adding comments as you write code is a good practice,because they provide clarification and understanding when you need to refer back to it, as well as for others who might need to read it.


Multi-line comments

Java also supports comments that span multiple lines.
You start this type of comment with a forward slash followed by an asterisk, and end it with an asterisk followed by a forward slash.
For example:


/* 
* This is also a Comment 
* Spanning multiple lines
*/

Note that Java does not support nested mutli-line comments.
However, you can nest Single-line comments within multi-line comments.


/*
* JavaSunderesan - MultiLine Comments 
// a Single Line Comment
*/

Documentation Comments

Documentation comments are special comments that have the appearance of multi-line comments, with the difference being that they generate external documentation of your source code. These begin with a forward slash followed by two asterisks, and end with an asterisk followed by an forward slash.
For Example:


/** Welcome To Java Sunderesan
* Copyright (C)2016 King  . All Rights Reserved
*/

Javadoc is a tool which comes with JDK and it is used for generating Java Code documentation in HTML format from Java source code which has required documentation in a predefined format.
When a documentation comment begins with more than two asterisks, Javadoc assumes that you want to create a "box" around the comment in the source code. It simply ignores the extra asterisks.
For Example:


/**********
* Welcome To Java Sunderesan Copyright (C)2016 King . All Rights Reserved
*/

No comments :

Post a Comment