Java Comment

In the future, we going to write lots of code in java.

It is a little difficult to remember your code after some time. So for this, we use comments while coding


What is the comment:

The comment is a description written by a programmer in the code to remember his code  and make it readable

  •  Comments are not executable part and it is ignored by java compiler
  • Comments are mainly used to help programmer to understand the code

Type  of comment:

types of comments in java

Single line comments:

  • To write Single line comment we can use  the  // symbol
  • The Single line comment is used to comment only one line

Example:

// "Hello, World!" program example
 
class Main {
    public static void main(String[] args) {    	
    {
        // prints "Hello, World!"
        System.out.println("Hello, World!");
    }
}
Hello, World!

Multi-line comments:

  • To write a multi-line comment we can use the  /*…*/ symbol
  • The multiline comments used to write a comment in multiple lines

Example:

/* This is an example of a multi-line comment.
 * The program prints "Hello, World!" to the standard output.
 */

class HelloWorld {
    public static void main(String[] args) {    	
    {	
        System.out.println("Hello, World!");
    }
}
Hello, World!

Documentation  comment:

  • To write Documentation  comment we can use  the  /**…..*/ symbol
  • The documentation comment is used to create documentation API.

Example:

/**
* The HelloWorld program implements an application that
* simply displays "Hello World!" to the standard output.
*
* @author  code life
* @version 2.0
* @since   2020-4-24 
*/
public class HelloWorld {

   public static void main(String[] args) {
      // Prints Hello, World! on standard output.
      System.out.println("Hello World!");
   }
}
Hello, World!



SHARE THIS PAGE





Important Link