![]() |
| 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
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
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
/** * @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) } } ============OUTPUT============ |
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.

0 Comments