Comment in Java: Single and Multiline Comment

A comment is a note written to a human reader of a program. The program compiles and runs exactly the same with or without comments.

In Java, there are two types of comment as follows

1. Single line comment

It starts with two forward slashes(//) and continues to the end of the line. For example:

// this is a single-line comment
x = 1; // a single-line comment after code

2. Multi-line comment

Java also provides a comment type that can span multiple lines

You start this type of comment with a forward slash(/) followed by an asterisk(*), and end it with an asterisk followed by a forward slash.

The start and end delimiters for this type of comment may be on the same line, or they can be on different lines. For example

/* This is a c-style comment */
/* This is also a
c-style comment, spanning
multiple lines */
Previous Post Next Post

Contact Form