Comments in Java

The java comments are statements that are not executed by the compiler and interpreter. The comments can be used to provide information or explanation about the variable, method, class or any statement.


Types of Comments in Java

Java support three types of Comments :
1) Single Line Comment
2) Multi Line Comment
3) Documentation Comment

Single Line Comment

This type of comment is used to comment only one line of code.
Syntax :

 // line......... 


//This is single line comment
class Example {
    public static void main(String arr[]) { 
       System.out.println("Hello Boss");  
       //Printing on console 
    }
}
Hello Boss

Multi Line Comment

Multi Line comment is used to comment more then one line of code in Java.

/*.........
...........
.........
......... */


/* This is Mult line comment
program written by -durgesh kumar

*/
class Example {
    public static void main(String arr[]) { 
       System.out.println("Hello Boss");  
       /*
        System - System is class present in java.lang package
        out - is reference variable of type PrintStream
        println()- is method of PrintStream class

       */ 
    }
}
Hello Boss

Documentation Comment

The documentation comment is used to create documentation API. To create documentation API, you need to use javadoc tool.
Syntax:

/**.......
......
......
..... */


/** This is Documentation  comment
@author  Durgesh Tiwari
@version 1.0

*/
public class Example {
    public static void main(String arr[]) { 
       System.out.println("Hello Boss");  
       
    }
}
Hello Boss

What is Javadoc?

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 requires documentation in a predefined format.

woman avatar