Skip to main content

IDENTIFIERS

IDENTIFIERS:

A name in java program is called identifier. It may be class name, method name, variable name and label name.  


Example:
           
       Class Collegetak
{
    publc static void main (String [] args)

{
 int x=20;
}
}
            
     In this code there are 5 identifiers
  1. Collegetak
  2. main
  3. String
  4. args
  5.  x

Rules to define java identifiers:

Rule 1: The only allowed characters in java identifiers are:
  •   a to z 
  •  A to Z 
  •  0 to 9 
  •  _ (underscore) 
  •  $ 

Rule 2: If we are using any other character we will get compile time error.
Example:

1) total_number-------valid
 2) Total#------------------invalid


 Rule 3:  identifiers are not allowed to starts with digit.

 Example:
  •  ABC123---------valid
  •  123ABC---------invalid 

Rule 4: java identifiers are case sensitive up course java language itself treated as case sensitive language. 

Example:

 class Test
{
 int number=10;
 int Number=20; 
int NUMBER=20; we can differentiate with case. 
int NuMbEr=30; 
}


Rule 5: There is no length limit for java identifiers but it is not recommended to take more than 15 lengths. 


Rule 6: We can't use reserved words as identifiers.
 Example: 
int if=10; --------------invalid


 Rule 7: All predefined java class names and interface names we use as identifiers. 

Example 1: 

class Collegetak
 {
 public static void main(String[] args)
int String=15; System.out.println(String);
 }
}

 Output: 15

Example 2:

class CollegeTak
public static void main(String[] args)
{
int Runnable=20;
 System.out.println(Runnable);
}
 output: 20


Even though it is legal to use class names and interface names as identifiers but it is not a good programming practice. 

Which of the following are valid java identifiers? 
  1. _$_   (valid)
  2. Ca$h (valid)
  3. Java2shre  (valid)
  4. all@hands  (invalid)
  5. 123abc (invalid)
  6. Total# (invalid)
  7. Int ( valid)
  8. Integer (valid)
  9. int   (valid)
NEXT TOPIC:RESERVED WORDS

Comments

Popular posts from this blog

DIGITAL MARKETING

DIGITAL MARKETING END TERM PRACTICAL PAPERS:

Industry Ethics and Legal Issues MCQ Questions With Answer

ETHICS ALL POSSIBLE QUESTION - SET 1 Q1. Before 16 Jan, How many states were already working in Startup India policies? a) 1 b) 3 c) 4 d) 7 Q2. Which of the following is not a part of Funding Innovation? a) Incubation Center b) Startup Yatra Funds c) Research Parks d) Manak Q3. For R& D, human resource started a new scheme for students a) Tinkering labs b) Manak c) Avishkar yojana d) Uchhatar Avishkar yojana Q4. Startup India Scheme? 1. Age should not be more than 3 years 2. Should develop innovative product. 3. Must be Private Limited Company/ Registered Partnership firm/ Limited Liability Partnership 4. Has patent granted in areas affiliated with the nature of business being promoted a) 1, 3 6) 1,2 and3 c) 2, 3 and 4 d) All of the above Q5. The period of business when an entrepreneur must position the venture in a market and make necessary adjustments to assure survival is called the: a) pre-Startup stage b) Startup singe ...

DATA TYPES

DATA TYPES:- Every variable has a type, every expression has a type and all types are strictly define more over every assignment should be checked by the compiler by the type compatibility hence java language is considered as strongly typed programming language . Java is pure object oriented programming or not?     Java is not considered as pure object oriented programming language because several oops features (like multiple inheritance, operator overloading) are not supported by java moreover we are depending on primitive data types which are non objects.  Diagram:  Except Boolean and char all remaining data types are considered as signed data types because we can represent both "+ve" and"-ve" numbers.  Integral data types : Byte: Size:  1byte (8bits) Maxvalue:  +127  Minvalue: -128  Range: - 128to 127[ 2 7  to  2 7 -1] The most significant bit acts as sign bit. "0" means "+ve" number and...