Java – Comments

Prev     Next

  • Comments are description given by the programmer within the program. So that if another programmer looks at the program,he can easily understand the program by reading the comments.
  • The characters or words or anything which are given in comments section won’t be considered by java compiler for compilation process and will be ignored by java compiler during compilation.

Example program for java comments:

Comments can be given in three ways inside a java program. They are,

  1. Single line comment
  2. Multi line comment
  3. Documentation comments

1. Single line comment in Java:

It starts with two forward slashes and continues to the end of the line.

Syntax:

 // This comment extends to the end of the line.
String welcome = “Hi”; //The text to print

2. Multi line comment in Java:

Multi line comment starts with forward slash followed by an asterisk, and end with an asterisk followed by a forward slash.

Syntax:

/*  This is a
comment used for
multiple lines */
/* This comment can also be used for single line also */

3. Documentation comments in Java:

Documentation comments starts with a forward slash followed by two asterisks, and ends with an asterisk followed by a forward slash. This comment contains descriptions about the code and is used to create API document.

Syntax:

/** This is a
documentation comment */

Prev     Next

Share this website !!!
Facebook Twitter Linkedin

1. Online Compilers - Compile & Run your C/C++ programs:

✅ Online Compilers

2. Ask your questions or clarify your/others doubts from,

✅ Online Discussion Forums by Fresh2Refresh.com





Close
We Support JALLIKATTU !!!
We Support JALLIKATTU!
By Fresh2Refresh.com
Show Your Support as well. Thanks!