To understand integer and floating-point numbers
To recognize the limitations of the numeric types
To become aware of causes for overflow and roundoff errors
To understand the proper use of constants
To write arithmetic expressions in Java
To use the
String type to manipulate character strings
To learn how to read program input and produce formatted output
This chapter teaches how to manipulate numbers and character strings in Java. The goal of this chapter is to gain a firm understanding of these fundamental data types in Java.
You will learn about the properties and limitations of the number types in Java. You will see how to manipulate numbers and strings in your programs. Finally, we cover the important topic of input and output, which enables you to implement interactive programs.
In Java, every value is either a reference to an object, or it belongs to one of the eight primitive types shown in Table 1.
Six of the primitive types are number types; four of them for integers and two for floating-point numbers.
Java has eight primitive types, including four integer types and two floating-point types.
Each of the integer types has a different range—Special Topic 4.2 on page 130 explains why the range limits are related to powers of two. The largest number that can be represented in an
int is denoted by
Integer.MAX_VALUE. Its value is about 2.14 billion. Similarly,
Integer.MIN_VALUE is the smallest integer, about −2.14 billion. ...