0% found this document useful (0 votes)
6 views3 pages

2.6 Java Comments

Uploaded by

mrnirajbro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

2.6 Java Comments

Uploaded by

mrnirajbro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Java Comments

The Java comments are the statements in a program that are not
executed by the compiler and interpreter.

Why do we use comments in a code?

o Comments are used to make the program more readable by


adding the details of the code.
o It makes easy to maintain the code and to find the errors easily.
o The comments can be used to provide information or explanation
about the variable, method, class, or any statement.
o It can also be used to prevent the execution of program code
while testing the alternative code.

Types of Java Comments

There are three types of comments in Java.

1. Single Line Comment


2. Multi Line Comment
3. Documentation Comment
1) Java Single Line Comment

The single-line comment is used to comment only one line of the code.
It is the widely used and easiest way of commenting the statements.

Single line comments starts with two forward slashes (//). Any text in
front of // is not executed by Java.

Syntax:

1. //This is single line comment

Let's use single line comment in a Java program.

CommentExample1.java

1. public class CommentExample1 {


2. public static void main(String[] args) {
3. int i=10; // i is a variable with value 10
4. System.out.println(i); //printing the variable i
5. }
6. }

You might also like