Java Comments

Last Updated: March 17, 2022

Comments are non-executable text in your Java source code. Comments are added so that humans can easily understand the code. Also, you can comment out the code when you do testing the code

Java comments are ignored by the Java compiler.

You can have single-line comments and multiline comments in Java.

Java single line comments

There are two ways to use single-line comments in Java.

  • // (single line comment)

// This is a single-line comment

System.out.println("Hello World");

Java multiline comments

Comment out multiple lines using /* */

Any code or text between /* */ are ignored by the Java compiler

int[] numbers = {125, 132, 95, 116, 110};
 for (int i = 0; i < numbers.length; i++) {
     System.out.println("Number is " + numbers[i]);