Comments in Java
Comments in Java holds the description or hint about the code or explanations of the methods, interfaces, classes, fields etc.
The question arises why we are using comments. The answer is very simple- with the help of these comment the coder or programmer find convenient to understand the logic of the program. The compiler ignore these comments and do not compile it.
Types of comment
Java supports two kinds of comments :
Implementation Comment
These comments are taken from C++ in Java which are delimited by /*...*/. These are use to describe the code implementation so that the code understanding becomes easy for others.
Document Comment
Document Comments are known as doc comment. Doc Comment are used to describe the code specification and about the whole program not just a snippet or a part of code implementation.
Example
Given below example will give you a clear idea about comment :
/* This is a multiline comment. */ // This is a single-line comment. /** This is a multiline javadoc comment */ /* File header */ public class MainClass{ /** This is a method */ public static void main(String[] argv){ // output System.out.println(); } }
Description of the Code
- The first comment style supports traditional C-language comments.
- The second comment style supports single line C++ comments.
- The third comment style is used by the javadoc documentation generation
tool.