Comments in Java.

Comments in Java

  • 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 saya that compiler ignores the comment.
  • java comments are statements that are not executed by the compiler.

Types of comments in Java

  • Single line comment
  • Multiline comment

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 statrts 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
*/
Next Post Previous Post
No Comment
Add Comment
comment url