(^480) | One-Dimensional Arrays
Java data types
Primitive
Integral Floating
point
boolean
Reference
float double
array interface class
byte longchar short int
Figure 10.1 Java Data Types
10.1 Atomic Data Types
Recall that a data typeis a set of data values, along with a set of operations on those values.
The definitions of integers and real numbers come from mathematics. Integer numbers are
the set of whole numbers from negative to positive infinity. The operations defined for them
are the arithmetic operations [specified by +,-,/(integer division),*, and modulus], assign-
ment, and the relational operations. Real numbers are the set of all numbers from negative
to positive infinity. The operations defined for them are the same as those for the integers,
except that integer division and modulus are excluded.
Because computers have finite capabilities, programming languages put limits on the
range of integers and the range and precision of real numbers. Java provides four types of
integer numbers that differ only in the range of values that they can represent in memory:
byte,short,int, and long. Java has two real (floating-point) types that differ only in the range
and precision that they can represent: floatand double.
Alphanumeric characters are the symbols that we use in written language. These sym-
bols vary from one natural language to another. The same is true of characters used to rep-
resent textual data in a computer. For many years, two character sets dominated the computer
world: ASCII and EBCDIC. In these character sets, each character occupies one byte in mem-
ory, giving 256 possible characters. Some of these characters are nonprintable control char-
acters used by the computer’s hardware. Unicode is a relatively new character set that uses
two bytes to represent each character. It was developed to include characters for writing
text in many natural languages. Unicode, which Java uses, contains ASCII as a subset.
The operations defined on alphanumeric characters are the relational operations and as-
signment. The ordering used by the relational operators is the collating sequence of the
character set. Although the collating sequence differs for different character sets, the letters
and digits are ordered as we would expect—that is, ‘A’ < ‘B’ < ‘C’... and ‘1’ < ‘2’ < ‘3’ ....
Different programming languages treat characters differently. In Pascal, for example, the
data type for a character is distinct. Arithmetic operations, when applied to character data, cause
compile-time errors. In C++, no real distinction is made between characters and numbers.
T
E
A
M
F
L
Y
Team-Fly®