Special Offer - Enroll Now and Get 2 Course at ₹25000/- Only Explore Now!

All Courses
Java Comments

Java Comments

May 1st, 2019

Java Comments

Java comments are the statements which are given just for the sake of giving information to the viewer. It has nothing to do with the program’s execution. By using comments we can give any information about the document or codes used in the program or any information about the author of the document. This comments can be given anywhere within the document.
Comments in java are of two types :

  • Single Line Comment
  • Multi Line Comment

Single Line Comment :

  • For single line comments, we use ‘//’.
  • By using this, only comments comprising single line can be given.

Example:

class Sample //This is class Sample
{ // Main method starts from here.
public static void main(String[] args)
{
System.out.println(“Hello”);
}
}

Multi Line Comment :

  • For multiline comments, we use ‘/*_ _ _ _ */’.
  • By using this symbol, comments comprising multiple lines can be given.
class Sample
{
/* This is a class,
which is printing a word ‘Hello’ */
public static void main(String[] args)
{
System.out.println(“Hello”);
}
}
We can use these comments for documentation also.

Example:

/* We are going to write a program,
to print a word */
// The author of this program is Mr.xyz
class Sample
{
__
__
}
Within comments, we can use anything like, characters, numbers, special characters, etc, since it is not going to execute.