Please enable JavaScript to use CodeHS

Chapter 2

Using Objects

2.8 Wrapper Classes: Integers and Doubles

Wrapper Classes

Creating Integer and Double Objects

Autoboxing and Unboxing

Autoboxing Example

Methods in the Integer and Double Class

Method Examples

Creating Integers

Using Doubles

Check Your Understanding

  1. Incorrect Correct No Answer was selected Invalid Answer

Exercise: Guess the number!

Vocabulary

Term Definition
Integer(int value) and Double(double value) Constructs a new Integer object or a new Double Object that represents the specified int or double value
Integer and Double Classes These classes are part of the java.lang package and Object class and have a number of useful methods.
Integer.MIN_VALUE and Integer.MAX_VALUE The minimum/maximum value represented by an int or Integer, which are -2147483648 and 2147483647
int intValue() and double doubleValue() Returns the value of this Integer as an int and this Double as a double
Autoboxing Automatic conversion between primitive types and their corresponding object wrapper classes
Unboxing Reverse of autoboxing; automatic conversion from the wrapper class to the primitive type