Comments in Java

Object Oriented ProgrammingJava8Java Programming

The Java language supports three types of comments −

Sr.No.
Comment & Description
1
/* text */
The compiler ignores everything from /* to */.

2
//text
The compiler ignores everything from // to the end of the line.

3
/** documentation */
This is a documentation comment and in general, its called doc comment. The JDK Javadoc tool uses doc comments when preparing automatically generated documentation.

Following is a simple example where the lines inside /*...*/ are Java multi-line comments. Similarly, the line which proceeds // is Java single-line comment.

Example

Live Demo

/**
* The HelloWorld program implements an application that
* simply displays "Hello World!" to the standard output.
*
* @author  Zara Ali
* @version 1.0
* @since   2014-03-31  
*/
public class HelloWorld {
   //Standard main method
   public static void main(String[] args) {
      /* Prints Hello, World! on standard output. */
      System.out.println("Hello World!");
   }
}

You can include required HTML tags inside the description part. For instance, the following example makes use of <h1>....</h1> for heading and <p> has been used for creating paragraph break −

Example

Live Demo

/**
* <h1>Hello, World!</h1>
* The HelloWorld program implements an application that
* simply displays "Hello World!" to the standard output.
* <p>
* Giving proper comments in your program makes it more
* user friendly and it is assumed as a high quality code.
*  
*
* @author  Zara Ali
* @version 1.0
* @since   2014-03-31  
*/
public class HelloWorld {

   //Standard main method
   public static void main(String[] args) {
      /* Prints Hello, World! on standard output.*/
      System.out.println("Hello World!");
   }
}
raja
Published on 23-Jul-2018 06:46:14
Advertisements