Basic Comments in Java

Whenever we want to write a program, we should first think about writing comments. What are comments? Comments are description about the features of a program. This means whatever we write in a program should be describe using comments. Why should we write comments? When we write comments, we can understand what the program is doing as well as helps others to easily follow our code. This means readability and understand ability of a program will be more. If a program is understandable, then only can it be usable in a software. If other members of the software development team can not understand our program, then they may not able to use it in project and will reject it. So writing comments is compulsory in any program. Remember, it is good programming habit.

There are three types of comments in Java.
1. single line comment
2. multi line comment
3. java documentation

Single Line Comments:
These comments are for making a single line as a comment. These comments start with double slash symbol // and after this, whatever we written till end of the line is taken as a comment.

Example:

//This is my comment of one line.

Multi Line Comments:
These comments are used for representing several lines as comments. These comments start with /* and end with */. In between /* and */, whatever is written is treated as a comment.

Example:

/* This is a multi line comment. This is line one.
This is line two of the comment
This is line three of the comment. */

Java Documentation Comments:
These comments start with /** and end with */. These comments are used to provide description for every feature in a Java program. This description proves helpful in the creation of a .html file called API(Application Programming Interface) document. Java Documentation comments should be used before every feature in the program as shown here:

/** description about the class */
Class code{

/** description about a method */
Method code(){

   }
}

<<Previous <<   || Index ||   >>Next >>

Previous
Next