The JavaTM Tutorial

| Start of Tutorial > Start of Trail > Start of Lesson | Search Feedback Form

Trail: Learning the Java Language
Lesson: Object Basics and Simple Data Objects

## Summary of Numbers

> You use an instance of one of the `Number` classes-`Byte`, `Double`, `Float`, `Integer`, `Long`, and `Short`-to contain a number of primitive type. You can also use `BigInteger` and `BigDecimal` for arbitrary-precision numbers.

> The `Number` classes include class methods and constants, which are useful in a variety of ways. The `MIN_VALUE` and `MAX_VALUE` constants contain the smallest and largest values that can be contained by an object of that type. The `byteValue`, `shortValue`, and similar methods convert one numeric type to another. The `valueOf` method converts a string to a number, and the `toString` method converts a number to a string.

> To format a number to display to an end user, you use the `NumberFormat` class in the `java.text` package. When using `NumberFormat`, you can get a default format for decimal numbers, percentages, or currency. Or, you can design a custom format using patterns.

> The `Math` class contains a variety of class methods for performing mathematical functions. This class includes the trigonometric functions, such as computing sine, cosine, and so on. `Math` also includes functions for logarithm calculations, as well as basic arithmetic functions, such as rounding. Finally, `Math` contains a method, `random`, for generating random numbers.

| Start of Tutorial > Start of Trail > Start of Lesson | Search Feedback Form

Copyright 1995-2001 Sun Microsystems, Inc. All rights reserved.