Comments in Java

Hello friends how are you, today in this blog i will teach you what is comment in Java, types of comment , details of each type of comment, how comment works and many programs using comment in a very simple way. 

Let's start
  • 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

  • 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.
  • if in a program you want to comment only a single line then you can use single line comment.
//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
*/

Request:-If you found this post helpful then let me know by your comment and share it with your friend. 
If you want to ask a question or want to suggest then type your question or suggestion in comment box so that we could do something new for you all. 

If you have not subscribed my website then please subscribe my website. 

Try to learn something new and teach something new to other. Thanks.😊

Post a Comment

0 Comments