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:
1 2 3 4 5 6 7 8 9 |
public class Studyopedia { public static void main(String[] args) { // Display a line System.out.println("This is demo text."); } } |
Output
1 2 3 |
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:
1 2 3 4 5 6 7 8 9 10 |
public class Studyopedia { public static void main(String[] args) { /* Display a single line with demo text */ System.out.println("This is demo text."); } } |
Output
1 2 3 |
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