.
Java Comment With Example
Java
Comments
Types Of Comments in Java
Example Documentation comment
- Java Comment is Used to hide the selected code.
- Comments are used to write a detailed description of application logic to understand the logic easily.
- When we write the comments the application maintenance will become easy.
- Comments are non-executable code these are ignored during compilation.
- Java Comment is used to provide the details or explanation of variables, methods, classes or any other statements
There are 3
types of java comments.
1) Single-line Comments
2) Multi-line Comments
3)Documentation Comments
1) Single-line Comments
A single-line comment is used to write the description in a single line.
Syntax of Single-line Comments
//description
Example of a Single line comment
public class Test
{public static void main(String[] args){
int x=40;//Here, xis a variable
System.out.println(x);
}
}
2) Multi-line Comments
Java Multi-line Comment is used To write the description in more than one line. Starts /* ends
*/
Syntax of Multi-line comment
/*
satement-1
Statement-2
;;;;;;;;;;;;;;
Statement-n
*/
Example of multi-line comment
public class Test
{public static void main(String[] args)
{/*This is an example ofMulti-line comment*/
int x=40;
System.out.println(x);
}
}
3)Documentation
Comments
In Java, Documentation Comments are Used to prepare API documents.
Syntax of Documentation Comments
/*
*statement-1
*statement-2
*/
0 Comments