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

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

SET 2

ETHIC MCQ- SET 2 Q101. SISHU stage of MUDRA loan scheme provides maximum amount of? a) RS 10 Thousand b) RS 20 Thousand c) RS 30 Thousand d) RS 50 Thousand Q102. A criminal activity within the information technology infrastructure. a) Digital crime b) Intellectual property c) Cyber-crime d) All of them Q103. Law is the system of rules of conduct established by the government of a society to maintain a) Justice b) Consistency c) None of these d) Both A & B Q104. ln which year Pradhan Mantri MUDRA Yojana was launched? a) 2015 b) 2016 c) 2014 d) 2013 Q105. Minimum how many numbers of directors required in Public company a) 9 b) 8 c) 3 d) 10 Q106. Which of the following is not considered while selecting the region? a) Law and order b) Price of land c) Availability of raw materials d) Proximity to the product market Q107. A genetic term that is concerned to the legal and regulatory aspects of Internet and computer technolo

DIGITAL MARKETING

DIGITAL MARKETING END TERM PRACTICAL PAPERS: