17 Jan Java Comments
Comments in Java allow you to describe the code. This makes the Java code easy to read. Whatever you add inside a comment never gets compiled. Comments in a Java program can be mentioned in the following two ways:
- Single-line Comment
- Multi-line Comments
Single-line comments
Use // i.e., two forward slashes for a single-line comment in Java. Whatever we mention after the slashes in a single line, will not get compiled.
Let us see an example displaying single-line comments in Java:
public class Studyopedia {
public static void main(String[] args) {
// Display a line
System.out.println("This is demo text.");
}
}
Output
This is demo text.
Multi-line comments
For multi-line comments in Java, use /* */. Whatever we mention under /* and */, will not get compiled.
Let us see an example displaying multi-line comments in Java:
public class Studyopedia {
public static void main(String[] args) {
/* Display a single line
with demo text */
System.out.println("This is demo text.");
}
}
Output
This is demo text.
If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.
For Videos, Join Our YouTube Channel: Join Now
Read More
No Comments