Java Tutorials
Java Methods
Java Classes
Java File Handling
Comments can be used to describe Java code, making it more readable. It may also be used to prevent usage when testing another code.
One-line comment starts with two forward slash (//
).
Any text between //
and end of line is ignored by Java (will not be used).
This example uses comments of one line before the line of code:
// This is a comment
System.out.println("Hello World");
This example uses a single line comment at the end of the code line:
System.out.println("Hello World"); // This is a comment
Multi-line comments start with /*
and end with */
.
Any text between /*
and */
will be ignored by Java.
This example uses multi-line comments (comment block) to define code:
/* The code below will print the words Hello World
to the screen, and it is amazing */
System.out.println("Hello World");
It is up to you to decide. Generally, we use //
short, and /* */
short comments.