Primitive vs Wrapper Types
Integer, Double, Boolean and friends.
Two Worlds of Values
Java has primitive types like int, double, and boolean that hold raw values directly. It also has wrapper classes like Integer, Double, and Boolean that wrap those values inside objects.
Primitives are fast and lightweight. Wrappers are full objects that can live in collections and can be null.
The Eight Primitives
Java defines exactly eight primitive types:
byte,short,int,longfor integersfloat,doublefor decimalscharfor a single characterbooleanfor true/false
Each has a matching wrapper class in the java.lang package.
All lessons in this course
- Primitive vs Wrapper Types
- Autoboxing and Unboxing
- Parsing and Valueof
- Autoboxing Pitfalls