Java Comments

christian.dinh's avatar
Published May 6, 2021Updated Sep 9, 2021
Contribute to Docs

A comment is a piece of text within a program that is not executed. It can be used to provide additional information to aid in understanding the code.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
    • Beginner Friendly.
      17 hours

Single-line Comments

In Java, single-line comments are created with two consecutive forward slashes //.

// I am a single-line comment!
System.out.println('Hello, world!');

A single-line comment can also be used to comment after a line of code:

System.out.println('Hello, world!'); // Me, too!

Multi-line Comments

Multi-line comments are created by surrounding the lines with /* at the beginning and */ at the end. Comments are good ways for a variety of reasons like explaining a code block or indicating some hints, etc.

/*
And I am a
multi-line comment!
*/

All contributors

Contribute to Docs

Learn Java on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
    • Beginner Friendly.
      17 hours