Comments in Java

In this tutorial, we will learn about Comments in Java. Comments are not used to perform any function in the program but they are really useful for developers. Developers can write comments with variables and Methods to remember their working (purpose) in the program. One important thing to mention comments doesn’t put any impact on the execution of program because compiler simply ignores them

Types of Comments:

  • Single Line comments
  • Multi-Line comments

Single-Line Comments:

Single Line comments are used to add single line comment with a variable or any Method. Double slash “//’ is used to add Single-Line comments.

public class Example{
   //This is show method to show data 
   public void show(){
     System.out.println("show method");
   }
   public static void main(String args[]){
      Example obj=new Example();
      obj.show();
   }
}

Multi-Line Comments:

Multi-Line comments are used to add a multi-line comment with a variable or any Method. /* */ symbols is used to add Multi-Line comments.

public class Example{
   /*This is show method to 
   show data */
   public void show(){
     System.out.println("show method");
   }
   public static void main(String args[]){
      Example obj=new Example();
      obj.show();
   }
}
Spread the love