Comments in Java Programming

In this Java tutorial, we are going to learn about creating comments.

Comments in programming do not change the functionality or how your program works but it plays an important role in documentation of your program.

There are 3 types of comments in Java Programming (single line comment, multi line comment and documentation comment).

Single line comment

It is a type of comment written in a single line manner.

Example:

// your comment goes here

Anything you place after the two forward slashes symbol // will be ignore by the compiler.

Multi line Comment

It is a type of comment written in one or more lines.

Example:

/* your comment goes here */

Or

/*

this is

an example

of multi line

*/

Anything you place between the /* */ will be ignore by the compiler.

Documentation comment

It is a type of comment written used for documentation of your source code.

Example:

/** example of documentation comment */

Or

/** This is also an example of

documentation comment */

Same as the previous types of comment the compiler will ignore anything you place between /** and */

Note:

  • It is a good practice to place comments to your program but don’t overuse it.
  • Avoid nested comments or a comment inside a comment (it may result to compiler error).
  • Comments will help you remind the functionality of your codes and most importantly it will help others understand your code.

Post navigation

One thought on “Comments in Java Programming

  1. Hello ,
    Great article! So well written -This is very helpful article for everyone. I wish to read more article from you! Thanks for sharing this valuable information!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.