Java – Comment

Java comments:

  • Comments are description given by the programmer within the program. So that if another programmer looks at the program,he can easily understand the program by reading the comments.
  • The characters or words or anything which are given in comments section won’t be considered by java compiler for compilation process. These will be ignored by java compiler during compilation.

Example program for java comments

/**
 * This program prints "Hi" to output screen.
 */
class Welcome{
    public static void main(String[] args) {
        String welcome = "Hi"; //The text to print
        System.out.println(welcome); /* Print the text 'Hi' */
    }
}

Comments can be given in three ways inside a C program.

1. Single line comment – Syntax :

It starts with two forward slashes and continues to the end of the line.

 // This comment extends to the end of the line.
String welcome = “Hi”; //The text to print

2. Multi line comment – Syntax :

Multiline comment starts with forward slash followed by an asterisk, and end with an asterisk followed by a forward slash.

/*  This is a
comment used for
multiple lines */ 

/* This comment can also be used for single line also */

Documentation comments:

Documentation comments starts with a forward slash followed by two asterisks, and ends with an asterisk followed by a forward slash. This description is used to create API document.

/** This is a
documentation comment */

Prev                                                                                                                                         Next