Comments in Java Programming Language

Comments in Java Programming Language
Comments in Java Programming Language

Comments in Java: Comments can be used to explain the source code to make it more readable Java program. A comment is a programmer readable annotation in source code. Comments are ignored by the compiler.
Comments are not considered as a part of program in other word we can say that compiler ignores the comment.
Comments are only understand the source code notes. Java compiler are skip comments lines. Comments make the code easier to understand and do not effect our Java program output.

Types of comments in Java

  • Single line comment
  • Multiline comment
  • Documentation comment

Single Line Comments in Java

Single line comment: It is used to comment only one line. Two forward slashes(//) is used for single line comment. Single line comment starts with double forward slashes.

How to Write Comments in Java

class Jiocoding{
public static void main(String[] args)
{
 //This line is a single line comments
 //This line not show the your output
//write a add two number program
int x=10; int y=60;

System.out.println("Addition of X+Y:"+(x+y));
}
}
============OUTPUT============
Addition of X+Y:70

Multiline Comments in Java 

Multiline comment: Java multiline comment is used to comment a block of code. It can be used multiple statements comments source code.

Multiline comment started with /* and ends with */. The text between /* and */ is not executed by the compiler.

Multiline Comments in Java Program

class Jiocoding{
public static void main(String[] args)
{
/*This line is a single line comments
This line not show the your output
write a add two number program  */
int x=40; int y=60;

System.out.println("Addition of X+Y:"+(x+y));
}
}
============OUTPUT============
Addition of X+Y:100

Documentation comments in Java

Documentation Comments: Document comment can be started with (/**) and ending with (*/).

It is a specifically designed to be processes by the Javadoc type.

Javadoc comments describe classes, interfaces, methods including details explain arguments return values.

It is  exceptions using special Javadoc attributes like @param, @return, @version, @sinceand  @throws.

Java Documentation Comments Example

class Jiocoding{
/**

* @param first number

* @param second number

 @return addition of two number

 */

public int add(int x, int y){

return x+y;

}

public static void main(String[] args){

Jiocoding jc=new Jiocoding();
System.out.println("Addiotn of x+y"+jc.add(10,50));
}
}
============OUTPUT============
Addition of x+y:60


Conclusion of Java Comments

Conclusion: This is a Java Comments it can be used Java source code reading a notes or understandable program. It is very important all programming language because comments can not be run only show the information. It is all about Java Comments if you have any query or doubt than you can contact me.


Java Programming Language

Post a Comment

0 Comments