Comments in Java programming Hands on coding

Comments in Java;

In this article we are going to see regarding comment lines.

Comments;

  •  It is used to explain the code to make it more readable.
  • It is not considered as a part of program, in other word we can say that compiler ignores the comment.
  • Java comments are statements that are not executed by the compiler.


Types of comments in Java;

  1. Single line comment
  2. Multiline comment

Let's see one by one.


Single line comment;

  • It is used to comment only one line.
  • Two forward slashes(//) is used for single line comment.
  • Single line comment starts with double forward slashes.

 //this is a single line comment   
 System.out.println("you are excellent");

Multiline comment;

  • Multiline comment is used to comment a block of code.
  • Multiline comment starts with / and ends with /.
  • The text between / and / is not executed by the compiler.
 class Easy   
 {   
   public static void main(String[] args)   
   {   
     /* This is multiline comment   
       Write a program to add two   
       number and store it in third number   
    */   
    int x,y=10,z=30;   
    x=y+z;   
    System.out.println("Add="+x);   
   }   
 }   
 / ### Output ### Add=40 /   

For Videos Join Our Youtube Channel: Join Now