Java Comments
Java Comments
HTML CSS
Menu Log in
Java Comments
❮ Previous Next ❯
Java Comments
Comments can be used to explain Java code, and to make it more readable. It can also
be used to prevent execution when testing alternative code.
Single-line Comments
Single-line comments start with two forward slashes ( // ).
Any text between // and the end of the line is ignored by Java (will not be executed).
Example
// This is a comment
System.out.println("Hello World");
Try it Yourself »
Example
Try it Yourself »
Dark mode
D k d
ADVERTISEMENT Dark code
HTML CSS
IEWAU
HUAWEI Mobile PH Ads by
WAUH
Stop seeing this ad Why this ad?
HUAWEI nova 10
Series
Shop Now
This example uses a multi-line comment (a comment block) to explain the code:
Example
Try it Yourself »
Exercise:
Insert the missing part to create two types of comments.
Dark mode
D k d
Dark code
HTML CSS
This is a single-line comment
This is a multi-line comment
Submit Answer »
❮ Previous Next ❯
ADVERTISEMENT
NEW
We just launched
W3Schools videos
Explore now
COLOR PICKER
Get certified
by completing Dark mode
D k d
Dark code
HTML CSS a Java
course today!
school
w3 s
2
CE
02
TI 2
R
FI .
ED
Get started
CODE GAME
Play Game
ADVERTISEMENT
Report Error
Spaces
Pro
Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial
Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference
Top Examples
HTML Examples
CSS Examples
JavaScript Examples
How To Examples
SQL Examples
Python Examples
W3.CSS Examples
Bootstrap Examples
PHP Examples
Java Examples
XML Examples
jQuery Examples
Get Certified
HTML Certificate
CSS Certificate
JavaScript Certificate
Front End Certificate
SQL Certificate
Python Certificate
PHP Certificate
jQuery Certificate
Java Certificate
C++ Certificate
C# Certificate
XML Certificate
FORUM | ABOUT
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and
learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant
full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use,
cookie and privacy policy.
Dark mode
D k d
Copyright 1999-2022 by Refsnes Data. All Rights Reserved. Dark code
HTML CSS W3Schools is Powered by W3.CSS.