Java Data and Operators

7. Character Data and Operators

Another primitive data type in Java is the character type, char. A character in Java is represented by a 16-bit unsigned integer. This means that a total of 216 or 65536 different Unicode characters can be represented, corresponding to the integer values 0 to 65535. The Unicode character set is an international standard that has been developed to enable computer languages to represent characters in a wide variety of languages, not just English. Detailed information about this encoding can be obtained at

http://www.unicode.org/

It is customary in programming languages to use unsigned integers to represent characters. This means that all the digits (0,...,9), alphabetic letters (a,...,z,A,...,Z), punctuation symbols (such as . ; , " '' ! -), and nonprinting control characters (LINE FEED, ESCAPE, CARRIAGE RETURN, ...) that make up the computer's character set are represented in the computer's memory by integers. A more traditional set of characters is the ASCII
(American Standard Code for Information Interchange) character set. ASCII is based on a 7-bit code and, therefore, defines 27 or 128 different characters, corresponding to the integer values 0 to 127. In order to make Unicode backward compatible with ASCII systems, the first 128 Unicode characters are identical to the ASCII characters. Thus, in both the ASCII and Unicode encoding, the printable characters have the integer values shown in Table 5.13.
TABLE 5.13 ASCII codes for selected characters
Code 32 33 34 35 36 37 38 39 40 41 42 43 44
Char SP ! " # $ % & ( ) * + ,
Code 48 49 50 51 52 53 54 55 56 57
Char 0 1 2 3 4 5 6 7 8 9
Code 58 59 60 61 62 63 64
Char : ; < = > ? @
Code 65 66 67 68 69 70 71 72 73 74 75 76 77
Char A B C D E F G H I J K L M
Code 78 79 80 81 82 83 84 85 86 87 88 89 90
Char N O P Q R S T U V W X Y Z
Code 91 92 93 94 95 96
Char [ \ ] ^ -
Code 97 98 99 100 101 102 103 104 105 106 107 108 109
Char a b c d e f g h i j k l m
Code 110 111 112 113 114 115 116 117 118 119 120 121 122
Char n o p q r s t u v w x y z
Code 123 124 125 126
Char { | } -