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

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 05-Jan-2018 12:43:03
Advertisements