Identify the identifiers as valid or invalid (reason if invalid) i. break ii. Program 1
Answers
Answer:
i) invalid (reserved keyword)
ii) valid
Explanation:
Rules for identifier:
- A valid identifier must have characters [A-Z] or [a-z] or numbers [0-9], and underscore(_) or a dollar sign ($).
- There should not be any space in an identifier.
- An identifier should not contain a number at the starting.
- We can't use the Java reserved keywords as an identifier such as int, float, double, char, etc.
- An identifier should not be any query language keywords such as SELECT, FROM, COUNT, DELETE, etc.
List of Valid identifiers:
1. xyz
2. fvariable
3. a
4. cal_sum
5. _product
6. $money
7. variable123
8. num
9. thisIsMe
10. hello_Me1
Refer to the attachment to see the list of reserved keywords(cannot be used as identifier).
Hey
Here's your answer
Rules for Identifiers:
1. The only allowed characters for identifiers are all alphanumeric characters([A-Z],[a-z],[0-9]), ‘$‘(dollar sign) and ‘_‘ (underscore).
2. Identifiers should not start with digits([0-9]).
3 . Java identifiers are case-sensitive.
4. There is no limit on the length of the identifier but it is advisable to use an optimum length of 4 – 15 letters only.
5.Reserved Words can’t be used as an identifier.
6. An identifier should not have a space.
Back to the question:
i) break - invalid
Reason: break is a reserved keyword, identifiers can't be a reserved keyword.
ii) Program 1 - invalid
Reason: Identifier cannot have a space.