Download the JDK
Search the Tutorials
Hide the TOC
Trail: Learning the Java Language
Lesson: Numbers and Strings
Section: Numbers
Numbers and Strings
Numbers
The Numbers Classes
Formatting Numeric Print Output
Beyond Basic Arithmetic
Summary of Numbers
Questions and Exercises
Characters
Strings
Converting Between Numbers and Strings
Manipulating Characters in a String
Comparing Strings and Portions of Strings
The StringBuilder Class
Summary of Characters and Strings
Questions and Exercises
Home Page > Learning the Java Language > Numbers and Strings
Summary of Numbers

> You use one of the wrapper classes – `Byte`, `Double`, `Float`, `Integer`, `Long`, or `Short` – to wrap a number of primitive type in an object. The Java compiler automatically wraps (boxes) primitives for you when necessary and unboxes them, again when necessary.

> The `Number` classes include constants and useful class methods. 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 string containing numbers for output, you can use the `printf()` or `format()` methods in the `PrintStream` class. Alternatively, you can use the `NumberFormat` class to customize numerical formats using patterns.

> The `Math` class contains a variety of class methods for performing mathematical functions, including exponential, logarithmic, and trigonometric methods. `Math` also includes basic arithmetic functions, such as absolute value and rounding, and a method, `random()`, for generating random numbers.

Previous page: Beyond Basic Arithmetic
Next page: Questions and Exercises: Numbers