Keywords
Keywords are reserved words or identifiers that are predefined in the language and cannot be used to denote other entities. All Java keywords are lowercase, and incorrect usage results in compile-time errors.
Keywords currently defined in the language are listed in Table 2.1. The keyword strictfp is obsolete as of Java SE 17, and its use is discouraged in new code. Contextual keywords that are restricted in certain contexts are listed in Table 2.2. Keywords currently reserved, but not in use, are listed in Table 2.3. In addition, three identifiers are reserved as predefined literals in the language: the null literal, and the boolean literals true and false (Table 2.4). A keyword cannot be used as an identifier. A contextual keyword cannot be used as an identifier in certain contexts. The index at the end of the book contains references to relevant sections where currently used keywords are explained.
Table 2.2 Contextual Keywords
exports | opens | requires | uses |
module | permits | sealed | var |
non-sealed | provides | to | with |
open | record | transitive | yield |
Table 2.3 Reserved Keywords Not Currently in Use
const | goto |
Table 2.4 Reserved Literals in Java
null | true | false |
Separators
Separators (also known as punctuators) are tokens that have meaning depending on the context in which they are used; they aid the compiler in performing syntax and semantic analysis of a program (Table 2.5). The semicolon (;) is used to terminate a statement. A pair of curly brackets, {}, can be used to group several statements. See the index entries for these separators for more details.
Table 2.5 Separators in Java
{ | } | [ | ] | ( | ) |
. | ; | , | … | @ | :: |
Literals
A literal denotes a constant value; in other words, the value that a literal represents remains unchanged in the program. Literals represent numerical (integer or floating-point), character, boolean, and string values. In addition, the literal null represents the null reference. Table 2.6 shows examples of literals in Java.
Table 2.6 Examples of Literals
Integer | 2000 | 0 | -7 | |
Floating-point | 3.14 | -3.14 | .5 | 0.5 |
Character | ‘a’ | ‘A’ | ‘0’ | ‘:’ ‘-‘ ‘)’ |
Boolean | true | false | ||
String | “abba” | “3.14” | “for” | “a piece of the action” |