Java Comments
Comments are utilized in Java to improve the readability and comprehensibility of the code to developers.
Single Line Comments
- Single-line comments begin with two forward slashes (//).
- Any material between // and the line end is not read by Java.
Example:
public class
Main
{
public static void main(String[] args) {
// This is a single line comment
System.out.println("Hello Coders!");
}
}
Output
Hello Coders!
Multi-line comments
- Multi-line comments begin with /* and end with */.
- Java will not read anything between /* and */.
Example:
public class
Main
{
public static void main(String[] args) {
/* This is a
multi line
comment */
System.out.println("Hello Coders!");
}
}
Output
Hello Coders!