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-Executable statement.

Why we make comment?

Why we make comment in program that question come in beginners mind. Basically comment are used 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 of comments in Java?

In Java language we have three types comments.

Single Line Comment

To make the single line comment we use two backword slash // symbol. 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 symbol /* */. 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 symbol /** */. 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 two no:- 30

Post Your Comment