Answer:
Yes. Sometimes your data is an integer, a primitive, but part of the program requires an object.
Type Wrappers
There is a division between primitive data
and objects.
The division sometimes needs to be crossed.
For each primitive type, there is a corresponding wrapper class.
A wrapper class can convert a primitive data value into an object.
Objects (of the correct class) can be converted into primitive data.
The table shows primitive types and their wrapper classes.
Java is case sensitive,
so byte and Byte are different types.
| primitive type | Wrapper type |
| byte | Byte |
| short | Short |
| int | Integer |
| long | Long |
| float | Float |
| double | Double |
| char | Character |
| boolean | Boolean |
As an example, the value 103 could be held in 32 bit section of memory
that is of primitive data type int.
The same value could be held in an object that is of type Integer.
The object will use many more than 32 bits.
The wrapper classes are defined in the package java.lang
and so (like all classes in that package) are automatically available to your programs.
QUESTION 18:
Is String a wrapper class?