2.1 The Elements of Java Programs | 49
Notice that each character is enclosed in single quotes (apostrophes). The Java compiler
needs the quotes to be able to differentiate between the character data and other Java ele-
ments. For example, the quotes around the characters ‘A‘and ‘+‘distinguish them from the
identifier Aand the addition sign. Notice also that the blank,‘ ‘, is a valid character.
How do we write the single quote itself as a character? If we write ‘‘‘, Java complains
that we have made a syntax error. The second quote indicates the end of the (empty) char-
acter value, and the third quote starts a new character value. To deal with this problem, Java
provides a special escape sequencethat allows us to write a single quote as a character. That
Data Storage
Where does our code get the data it needs to operate? Data is stored in the computer’s memory.
Recall that memory is divided into a large number of separate locations or cells, each of which
can hold a piece of data. Each memory location has a unique address we refer to when we store
or retrieve data. We can visualize memory as a set of post office boxes, with the box numbers
serving as the addresses used to designate particular locations.
Of course, the actual address of each location in memory is a binary number in a machine
language code. In Java, we use identifiers to name memory locations; the compiler and the JVM
then translate those identifiers into binary form for us. This translation represents one of the
advantages provided by a high-level programming language: It frees us from having to keep
track of the numeric addresses of the memory locations in which our data and instructions are
stored.
100 101 102 103 104 105 106 107 108 109
110 111 112 113 114 115 116 117 118 119
120 121 122 123 124 125 126 127 128 129
130 131 132 133 134 135 136 137 138 139
140 141 142 143 144 145 146 147 148 149