Share on Google+Share on Google+

Java Comments - Java Tutorials

java comments

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.


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


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. 





Posted on: April 18, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Java Comments - Java Tutorials  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image