Comments, Identifiers, keywords in Java


Definition -

A description about a basic programming element is called comment.

Types of comments -

Java Supports 3 types of comments.
1. Single line comment - //
2. Multiline comment - /* */
3. Document comment - /** */

The statement placed inside these special character are ignored by compiler while compiling the class. It means, compiler will not generate bytecodes for those comments. So comments are not appeared in .class file.

  * This program shows adding two integer numbers.
  * @Author : Namdeva
  * @Company : JavaTechWorld
  * @Version : 1.0
public class Addition {
       /* This method take two integer number and return
          their addition result
       public static void add(int a, int b) {
              //adding and returning result
              return a+b;

Identifier and its rules -

Definition -

Identifier is a name of the basic programming elements.

Find out identifiers in the below program

Identifiers in Java

Rules in defining identifier

While defining identifier we must follow rules, else it leads to compile time error.

  1. Identifiers should only contail
    1. Alphabets                     [a to z] and [A to Z]
    2. Digits                             [ 0 to 9 ]
    3. Special characters       [ _ to $ ]
  2. Identifier should not start with a digit. A digit can be used from second character onwards.
    1. Example -    1stStudent is wrong,           No1Student is correct.
  3. Identifier should not contain special characters, the only '_' or '

1 thought on “Comments, Identifiers, keywords in Java

Leave a Comment

%d bloggers like this: