For instance, when you type an ???A???, the keyboard sends the integer value 65,
the integer code for ???A???, to the computer. The code for ???B??? is 66, etc. Lowercase characters have different codes.
For instance the integer code for ???a??? is 97, and the code for ???b??? is 98. So letters are just integers underneath,
and software treats the bits as numbers or character codes depending on the context.
The Java primitive types, by category, are these:
1 integral types
byte 8 bits wide ??’128 to 127
short 16 bits wide ??’32768 to 32767
int 32 bits wide ??’2 billion to 2 billion
long 64 bits wide very small (??’263) to very big (263 ??’1) integers
char 16 bits wide Java uses ???Unicode??? character codes
2 floating-point types
float 32 bits wide +/??’ 3.4 ?— 1038 with 6??“7 significant decimal digits
double 64 bits wide +/??’ 1.8 ?— 10308 with 14??“15 significant decimal digits
3 boolean type
boolean logical true or false
Among the integer and floating-point types, the cost of computing with greater precision is that the
higher-precision types require more space to store, and computations involve larger numbers of bits.
Here is an example Java program that uses only primitive data types:
public class Primitive {
public static void main( String[] args ) {
int x;
int y;
int z;
y = 7;
z = 4;
x = y + z;
System.
Pages:
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190