.


Divya

Java comment


A comment in Java programming is a statement that is not executed when the program is run. The only purpose of the comment is to be read by someone who is looking at the code.

Comments can be used to:

  • Let others understand what you are doing
  • Remind you what you are doing in past. Most of the programmer when they come to edit their project that he did in past.In that case comment help us to remind what we write in the code.

Java supports several ways of commenting:

  • Single Line Comment
  • Multi Line Comment
  • Documentation Comment

Single line comment

The single line comment is used to comment single line of code.

Syntax

//This is single line comment

Example

public class CommentExample {
public static void main(String[] args) {
int a=10;//Here, a is a variable
System.out.println(i);
}
}

Output : 10

Multi Line Comment

The multi line comment is used to comment multi line of code.

Syntax

/*
This
is
multi line
comment
*/

Example

public class CommentExample2 {
public static void main(String[] args) {
int a=10;
int b=20;
int c=30;
System.out.println(a);
/*System.out.println(b);
System.out.println(b); */
}
}

Output : 10

Documentation Comment
The java documentation comment is used to create a document for the project or code.

**
* The HelloWorld program implements an application that
* simply displays "Hello World!" to the standard output.
* * @author James Gosling
* @version 1.0
* @since 2014-03-31
*/ public class HelloWorld {
public static void main(String[] args) {
/* Prints Hello, World! on standard output.
System.out.println("Hello World!");
}
}

The javadoc tool recognizes only this type of comment.



.