Final answer:
Wrapper classes in Java are used to convert primitive data types into objects, which is necessary for use with collections and generics. The eight primitive types each have their own wrapper class. Autoboxing and unboxing are the automatic conversions between these primitives and their corresponding wrapper objects.
Step-by-step explanation:
Wrapper classes in Java are classes that encapsulate a primitive data type into an object. This is often necessary because generics and collections in Java work with objects and not primitive types. Each primitive data type in Java has a corresponding wrapper class.
The available wrapper classes in Java are:
- Byte - wraps the primitive byte
- Short - wraps the primitive short
- Integer - wraps the primitive int
- Long - wraps the primitive long
- Float - wraps the primitive float
- Double - wraps the primitive double
- Character - wraps the primitive char
- Boolean - wraps the primitive boolean
Autoboxing is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes. For example, converting an int to an Integer object. Unboxing is the reverse process where the wrapper class is converted back to a primitive type. For example, converting an Integer to an int.