Java : Types of Comments

Java comments are used to provide information or description about the class, statements, variable and method for future reference so that easy to understand code for future enhancement. Java comments statements don’t compile. It also helps to hide unused code.

Types of Java Comments

Java supports 3 types of comments statments:

  1. Single Line Comment
  2. Multi line Comment
  3. Documentation Comment
Java Comments Type
Java : Types of Comments

Single Line Comment

Single line comment statement is use to comment single line.

//Single line commnet statement

Multi Line Comment

Multi line comment statement is use to comment multiple line.

/*Multi line 
 *commnet statement

Documentation Comment

The documentation comment statement is used to create documentation of APIs. To generate documentation of API, you need to use the Javadoc tool.

 *Multi line 
 *Java doc
 *commnet statement

See Also: How to generate Java doc by command line and Eclipse IDE

Comments Type Example

In this Calculator example all types of comments.

 * This is a calculator class to perform
 * mathematical operations
 * @author saurabh.gupta1
public class CalculatorTest {

public static void main(String[] args) {

CalculatorTest calculator=new CalculatorTest();
//Calling add method to get sum of
int sum=calculator.add(10, 20);

* This is System method to
* debug logs statement in console
System.out.println("Sum of A =10 and B=20 is "+sum);
* This method add passing values
* and return sum
* @param a
* @param b
* @return
public int add(int a, int b)
return a+b;


 Sum of A =10 and B=20 is 30

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s