Comments
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 amulti-line comment!*/
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Java on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Java
Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.Beginner Friendly16 hours