Comments in java code
The comment in the computer
programming language is a piece of code for user understanding and they are
added to help humans to understand and easy to read. The comment is generally
not read by the compiler and interpreter. And comments are a very essential part
of computer programming language.
How many types of comments in java?
- Single line comments
- Multi-line comments
- Java doc comments
Single
line comments in java (//): This comment is used in single
line code
Syntax:
// This symbol is a single-line comment
Example
// class started (Single
line comment)
public class Summation
{
public static void main(String args[])
{
int a, b, c; //
Local variable
a = 10;
b = 30;
c = a + b;
System.out.println(c);
}
} // class end
Multi line comments in java (/* */):
This symbol is used for multi-line comment
Syntax:
/*
This symbol is an example
Of multi-line comment
*/
Example
/* class started Multi
line comment)
Comment contains more then
One-line
*/
public class Summation
{
public static void main(String args[])
{
/* a, b and c
Are local variable
*/
int a, b, c;
a = 50;
b = 70;
c = a + b;
System.out.println(c);
}
} // class end
Java document comments
This
comment more or less the same as the multi-line comment with one difference, it
start with /** (with two-star) and it is used to generate Javadoc comment.
/**
This program takes two number in a, b
And add the number to variable c
And print the c
*/
class MyClass
{
public static void main(String args[])
{
int a, b, c;
a = 80;
b = 90;
c = a + b;
System.out.println(“Summation=”
+ c);
}
}