Skip to main content

Identifiers

Identifiers:
                                    A name in java program is called identifier, which can be used for identification purposes. It can be a method name, variable name, class name, or label name.


Rules for defining java identifiers:
  1. The only allowed characters in java identifiers are a - z, A - Z, 0 - 9, $, and _. If we are using other characters, we will get a compile-time error.
  2. Identifiers can't start with digits.
  3. Java identifiers are case sensitive. Of course, java is treated as case sensitive programming language.
  4. There is no limit for java identifiers but it is not recommended to take too lengthy identifiers.
  5. We can't use reserved words as identifiers.
  6. All predefined java class name and interface name we can use as identifiers.
                    e.g.
                        int String = 888;
                        int Runnable = 999;

                        Even this is valid, but it is not good programming practice.



Examples

Que 1) How many identifiers in the following program?
                            
                                class Test{
                                            public static void main(String args[]){
                                                    int x = 10;
                                            }
                                }

Ans:      Five
               They are Test, main, String, args, x.


Que 2) Which of the following are valid java identifiers?
    1.   tot_num                        Valid
    2. total#                              Invalid
    3. 123totoal                        Invalid
    4. total123                          Valid    
    5. ca$h                                Valid 
    6. _$_$_$_$_                     Valid
    7. arr@share                      Invalid
    8. Java2share                     Valid
    9. Integer                           Valid
    10. Int                                  Valid
    11. int                                  Invalid         

Comments

Popular posts from this blog

Literals

Literals:                 Any constant value which can be assigned to the variable is called literal.     1 . Integer Literals:                                        For integral data types ( byte, short, int, long ), we can specify a literal value in the following base...                         a) Decimal literal (base 10):                                                     Allowed digits are 0 to 9.                               ...

JAVA HISTORY

History of JAVA:                                                                       Java is the  object-oriented, general-purpose programming language developed by  James Gosling, Patrick Naughton, Chris Warth, Ed Frank, and Mike Sheridan at Sun Microsystems, in 1991. Actually, Java was designed for the development of software for electric devices. It took 18 months to run the first version. This language was initially called "Oak", but was renamed as "JAVA" in 1995. Java Features:                              Java has bundles of features, they are as follows:           1) Object-oriented           2) High performance  ...