What is the difference between /* */ and /** */ comments in Java?


Multiline comments (/* */) are used to comment multiple lines in the source code.

Example

Live Demo

public class CommentsExample {
   /*
      Following is the main method here,
      We create a variable named num.
      And, print its value    
   * */
   public static void main(String args[]) {
      //Declaring a variable named num
      int num = 1;
      //Printing the value of the variable num
      System.out.println("value if the variable num: "+num);
   }
}

Output

value if the variable num: 1

Documentation comments (/** */) are used to generate a documentation on the source code using the Javadoc tool.

Example

Live Demo

/**
   * @author Tutorialspoint
*/ 
public class CommentsExample {
   public static void main(String args[]) {
      int num = 1;      
      System.out.println("value if the variable num: "+num);
   }
}

Output

value if the variable num: 1

You can generate Java documentation of the above class using the Javadoc command as −

C:\Sample>javadoc CommentsExample.java

Updated on: 30-Jul-2019

500 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements