Subscribe Us

Comment in Java and Types of Comment in Java

.
Comment in java
In a program , Comment are a portion of program that are not executed by the compiler and interpreter.

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

Types of Comment in java 
java comments divided into 3 sub-parts
1)Single line comment 
2) Multi line comment 
3) Documentation Comment 

Single Line Comment 

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

Syntax  

//This is syntax of single line comment 

Example 

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

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

Multi line Comment 

To comment multiple line of code in java use multiline comment . Use /*   */ to comment multiline code .

Syntax 

/* This is 
    Multi line 
    Comment in
    Java */

Example 

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

Documentation Comment 

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

Syntax

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

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

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

Thank You !
Sandeep Yadav

Tags : Comment in java , types of comment in java , java comment , single line comment in java , multiline comment in java , use of java , javadoc , syntax of multiline comment , example of comments , comment types in java ,
Comment in Java and Types of Comment in Java

Post a Comment

0 Comments