Decoding Java Identifiers: Comprehensive Notes and Insights

language fundamentals

Identifiers:- A name in java program is called identifier it may be class name, method name, variable name and label name.

IDE

Example:-

   

 Class Test

 {

 public static void main(String args[])

 {

            int x=10;

 }

 }

 

  • Test:- class name.
  • Main:- method name.
  • String:- predefined class name.
  • args:- variable name.
  • X:- variable name.

Rules for defining Java Identifiers:- There are certain rules for defining a valid java identifier. These rules must be followed; otherwise we get compile-time error. These rules are also valid for other languages like C,C++.

  • The only allowed characters for identifiers are all alphanumeric characters ([A-Z],[a-z],[0-9]), ‘$‘(dollar sign) and ‘_‘ (underscore).For example “daisy@” is not a valid java identifier as it contain ‘@’ special character.
  • Identifiers should not start with digits([0-9]). For example “123daisy” is a not a valid java identifier.
  • Java identifiers are case-sensitive.
  • There is no limit on the length of the identifier but it is advisable to use an optimum length of 4 – 15 letters only.
  • Reserved Words can’t be used as an identifier. For example “int while = 20;” is an invalid statement as while is a reserved word.

Leave a Comment

Your email address will not be published. Required fields are marked *