How to write single line comment in Java?

Java 8Object Oriented ProgrammingProgramming

To comment a particular line just place ‘double back slash (//)’ before the line as shown below.

// Hello this line is commented


Following example demonstrates the usage of single line comments in Java.

Live Demo

public class CommentsExample {
   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);


value if the variable num: 1
Updated on 30-Jul-2019 22:30:20