Identifiers are names of packages, classes, interfaces, methods, and variables. Though identifying a valid identifier is not explicitly included in the exam objectives, there’s a good chance that you’ll encounter a question similar to the following that will require you to identify valid and invalid identifiers:
Question: Which of the following lines of code will compile successfully?
- byte exam_total = 7;
- int exam-Total = 1090;
The correct answer is (a). Option (b) is incorrect because hyphens aren’t allowed in the name of a Java identifier. Underscores are allowed.
2.2.1. Valid and invalid identifiers
Table 2.7 contains a list of rules that will enable you to correctly define valid (and invalid) identifiers, along with some ...