7. Numbers

Working with numbers in Java is a subject that every programmer should become proficient in, as nearly every program deals with numbers of one form or another. In this chapter, we primarily use the basic numeric Java types, their object wrappers, and the java.lang.Math class.

Table 7.1 summarizes the built-in types that Java offers and lists their wrapper objects available. Note that the boolean type does not have a bit size because it can contain only two discrete values, a value of true or false.

Table 7.1. Java’s Built-In Types
TypeSize in bitsWrapper Object
byte8Byte
short16Short
int32Integer
long64Long
float32Float
double64Double
char16Character
boolean--Boolean

The object wrapper classes are useful when you want to treat a basic type ...

Get Java™ Phrasebook 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.