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.

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