Java Comments

In this tutorial, You'll learn about java comments. The Java comments are statements of a java program that the java compiler and interpreter discards or ignores or simply does not execute.

Java Comments

The purpose of java comments is only to allow the programmer to insert some informative notes or descriptions to enhance the understandability of the java program. Sometimes, the Programmers used comments to hide the lines of programs.

Java Comments and 3 types of Java Comments


Types of Java Comments

There are 3 types of comments in java. 
  1. Single Line Comment
  2. Multi Line Comment
  3. Documentation Comment

Single Line Comment

The single line comment begins with two forward slashes (//). Any text after the // is ignored (not execute) by the compiler but in the same or one line only.

Syntax

// Single Line Comment written here
  

Example

import java.lang.*;
class Simple{
public static void main(String args[]){
   System.out.println("HelloWorld"); // Print Hello World on Display.
   }
}
  

Multi Line Comment 

The multi line comment begins with /* and ends with */. Any text between this /* and */ is ignored (not execute) by the java compiler. It can be on different lines.

Syntax


    /*
    Multi Line 
    Comment Written Here
    */
  

Example

import java.lang.*;
class Simple{
public static void main(String args[]){
   System.out.println("Codeamy.in");
/*
This is Multi 
Line Comment
Example
*/
   }
}
  

Documentation Comment

The comment begins with /** and ends with */. Documentation comment is used to automatically generate documentation. To create documentation, You need JDK tool 'javadoc'. 


Syntax


    /**
    *Documentation
    *Comment Written Here
    */
  

Example

/**
* The Java program 
*  to print Codeamy.in
*
* @author  Veer Bhadra Solanki
* @version 1.0
* @since   2020-12-28
*/
import java.lang.*;
class Simple{
public static void main(String args[]){
   System.out.println("Codeamy.in");
   }
}
  
In this tutorial, You learn Java comments and 3 types of comments in java. 

Happy Coding 😊

If you have any doubts, Please let me know

Previous Post Next Post

Contact Form