What is comments in Java.?

Java program contain group of statement. All statement execute in program but some of the statement not execute. That are called comment statement. Comment are the Java program statement which will not execute. We can also say it None-Executeable statement.

Why we make comment.?

Why we make comment in program that question come in beginner programmer mind. Basically comment are use to provide the some useful information or some small documentation about the program. Most of the time we use comment statement in large program.

What is the advantage of Comment.?

How many types comment are there in Java.?

In Java language we have two types comments.

Single Line Comment

To make the single line comment we use two backword slash ( // ) symbole. This is called single line comment statement. In this program we are giving the information about the program by comment section. Comment section never will execute.

Now see the program code. By comment we are giving the information about the program logic. Like we are printing the message.

Syntax of single line comment:


    class Hello
    {
    	public static void main(String args[])
        {
            //Printing the message
            System.out.println("Welcome to campuslife");
        }
    }

Output


	Welcome to campuslife
    

Multiline Comment

To make the Multiline comment we use two backword slash with two astric symbole ( /* */ ) symbole. This is called multiline comment statement. In this program we are giving the information about the program by comment section. Comment section never will execute.

Now in this program code we are making multiline comment by giving more information.

Syntax of Multiline comment:


    class Hello
    {
    	public static void main(String args[])
        {
            /*Printing the message
            and show on the console window*/
            System.out.println("Welcome to campuslife");
        }
    }

Output:


	Welcome to campuslife
    

Documentation Comment

Documentation comment is used to create own API ( Application Programming Interface) document. To make the documentation comment we use two backword slash with three astric symbole ( /** */ ) symbole. It is also called a doc comment.

Syntax of Documentation comment:


	class Hello
    {
    	/**
        Calculation Program.
        To perform addition of two no.
        Three varibale is required
        Program version 1.0
        */
        public static void main(String args[])
        {
            int a=10,b=20,c;
            c=a+b;
            System.out.println("Sum of two no:- "+c);
        }
    }

Output


	Sum of tow no:- 30

Advertisement here

Share this Page.