Comments in java & Types of Comments

What is the comments in Java?

In a programming Language, Comments are a portion of the program that is not executed by the compiler and interpreter.


Use of java comments 
  • To make program code readable use java comments.
  • Java comments are used for Java code explanation (like method, variable or other information ).
  • java comment is used to prevent the execution by the compiler and interpreter.
  • Java comments are used to hide the code for a specific time period.

Types of Comments in java 
java comments divided into 3 sub-parts
1)Single line comments 
2) Multiline comments 
3) Documentation Comments 

1)Single Line Comments 

To comment on a single line code in java use a single line comment. We use // to comment a single line code.

Syntax: Syntax of single-line comment is as given below.

//This is the syntax of single-line comment 

Example: Examples of single-line comment is listed below.

public class JavaComment
 {  
public static void main(String[] args) 

{  
    int a=100;//Here, a is a variable  
    System.out.println(a);  
}  
}

Output:100

2)Multi-line Comments 

To comment on multiple lines of code in java use a multiline comment . Use /*   */ to comment multiline code .

Syntax 
: Syntax of multi-line comment is as given below.
/* This is 
    Multi line 
    Comment in
    Java */

Example
: Examples of multi-line comment is listed below.

public class JavaComment
 {  
public static void main(String[] args) 
{  
/*here int a= 100 is 
   local variable */
    int a=100; 
    System.out.println(a);  
}  
}

Output: 100

3)Documentation Comments 

To create a documentation API use java documentation comment. To create documentation API you can use the Javadoc tool instead of these comments.In java documentation comment starts with /** and ends with */.

Syntax
: Syntax of the document comment is as given below.

/** 
*This  
*is  
*documentation  
*comment */

Example: Examples of document comment is listed below.

/** 
*Project Name- upcs.in   
*Start Date - 12/02/20202  
*End Date - 12/03/2020
*@Author- Sandeep Yadav
 */
public class JavaComments
 {  
public static void main(String[] args) 
{  
    int a=100; 
    System.out.println(a);  
}  
}

Output: 100

Hope !!! The above lesson " Comments in Java" is Helpful For You...

Technology Team, 

UPCS 
UP Consultancy Services 

Tags : Comments in java, types of comments in java, java comments, single-line comments in java, multiline comments in java, use of java, javadoc , syntax of multiline comments, example of comments, comments types in java,

Comments in Java Types of Comments in Java