What is comments in JAVA ?


Comments in JAVA

JAVA comments are statements that are not executed by the Compiler and Interpreter. The comments can be used to provide information or explanation about the variables, methods, class or any statement. It can also be used to hide program code for specific time.

There are three types of Comments in JAVA :-

  1. Single-line Comment :-                                      
  2. Multi-line Comment :-                                          
  3. Documentation Comment :-

What is comments in JAVA ?
Comments in JAVA

1)- Single line Comment :-

It is used for comment only for one line.

Syntax :- //this is single line comment.

ex :-

class test1
{
    public static void main(String args[])
    {
           int n=10; //here n is a variable.
           System.out.println(n);
     }
}



1)- Multi-line Comment :-

Multi-line Comments are two or more than two line comments.

Sytanx :-  /*
                  This is 
                  Multi-line 
                  Comment.
                */

Ex :-

class test1
{
    public static void main(String args[])
    {
           /* this is 
               a java
               program
           */
           int n=10; 
           System.out.println(n);  
     }
}


3)- Documentation Comment :-

The Documented Comments are used to create documentation API you need to use JAVA_doc tool. The JDK Java_doc automatically prepares document.

Syntax :-   /**
                   This is 
                    Documentation 
                    Comment.
                 */

Ex :-  

        /** here we are creating a add1 class */
         public class add1
         {  
       /** The add() method returns addition of given numbers.*/     
        public static int add(int a, int b)
        {
         return a+b;
        }  
      /** The sub() method returns subtraction of given numbers.*/   
       public static int sub(int a, int b)
       {
         return a-b;
       }  


  Compile it  by  Javac tool :-

javac add1.java

Create Documentation API by Javadoc tool :-

Javadoc  add1.java

                                                                                     Thank You!!!

/

Post a Comment

0 Comments