Chapter 2. Lexical Elements

Java source code consists of words or symbols called lexical elements or tokens. Java lexical elements include line terminators, whitespace, comments, keywords, identifiers, separators, operators, and literals. The words or symbols in the Java programming language are comprised of the Unicode character set.

Unicode and ASCII

Unicode is the universal character set with the first 128 characters being the same as those in the American Standard Code for Information Exchange (ASCII) character set. Unicode provides a unique number for every character, given all platforms, programs, and languages. Unicode 5.0.0 is the latest version, and you can find more about it at http://www.unicode.org/versions/Unicode5.0.0/.

Tip

Java comments, identifiers, and string literals are not limited to ASCII characters. All other Java input elements are formed from ASCII characters.

The Unicode set version used by a specified version of the Java platform is documented in the class Character of the Java API.

Printable ASCII Characters

ASCII reserves code 32 (spaces) and codes 33 to 126 (letters, digits, punctuation marks, and a few others) for printable characters. Table 2-1 contains the decimal values followed by the corresponding ASCII characters for these codes.

Table 2-1. Printable ASCII characters

32 SP

48 0

64 @

80 P

96 '

112 p

33 !

49 1

65 A

81 Q

97 a

113 q

34 "

50 2

66 B

82 R

98 b

114 r

35 #

51 3

67 C

83 S

99 C

Get Java Pocket Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.