Chapter 7. Numbers


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

Type

Size in bits

Wrapper Object

byte

8

Byte

short

16

Short

int

32

Integer

long

64

Long

float

32

Float

double

64

Double

char

16

Character

boolean

--

Boolean


The object wrapper classes are useful when you want to treat a basic type like an object. For example, this might be useful if you want to define an API in terms of objects only. When wrapped as objects, the basic types can also be serialized.




JavaT Phrasebook. Essential Code and Commands
Java Phrasebook
ISBN: 0672329077
EAN: 2147483647
Year: 2004
Pages: 166

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net