2.2. Identifiers

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?

  1. byte exam_total = 7;
  2. 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 ...

Get OCA Java SE 8 Programmer I Certification Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.