Chapter 2. How Wholesome Are the Integers?

Compared with what we saw of the floating-point types in Chapter 1, the integer types must seem pretty tame and safe! We'll see how valid that assumption is in this chapter.

Java has five integer types named by the keywords byte, short, char, int, and long. The values of these types represent the whole numbers of pure mathematics, which we use for counting and for doing arithmetic that doesn't involve fractions. We must use the word represent because Java's integers, unlike the whole numbers, are not infinite.

The Integer Types and Operations

Table 2-1 shows the bit size, the minimum value, and the maximum value of each of Java's integer types.

Except for type char, which does not have negative values, the ...

Get Java™ Number Cruncher: The Java Programmer's Guide to Numerical Computing 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.