JAVA COMMENTS

 

JAVA COMMENTS 

Why write Java comments?

Java comments, as the name suggests, are notes you write between the programs for various reasons. For example, you may write comments to –

  • write information or explanation about the variable, method, class or any statement.
  • write text to be available in Java docs.
  • hide program code for specific time, etc.

Types of Java Comments

There are 3 types of comments in Java.

SINGLE LINE COMMENT 

Use single line comment when comment can be written in a single line only. These comments are written over Java statements to clarify what they are doing.

SYNTAX:

// Single line comment 

MULTI LINE COMMENT

Use multi-line comments when you need to add information in source code which exceeds to more than one line. Multi-line comments are used mostly above code blocks which have complex logic that cannot be written in single line.

SYNTAX:

/* Multi line comment */

DOCUMENTATION COMMENT

The documentation comments are used when you want to expose information to be picked up by the javadoc tool. This is the information you see in editors (e.g. eclipse) when using autocomplete feature. These comments are pit above classes, interfaces and method definitions.

SYNTAX: 

/** Documentation comment */