# Autoboxing And Unboxing

Autoboxing is the automatic conversion of a primitive data type to an object of the cor- responding wrapper class (you box the primitive value). Unboxing is the reverse process (you unbox the primitive value).

![](https://2172743581-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-La4k4liN--SZ6ay4iod%2F-LcyefyXy8J-D24U0u0N%2F-Lcyf7gGZ0a8-Ca-iEKk%2FScreen%20Shot%202019-04-21%20at%2012.23.51%20PM.png?alt=media\&token=f252ac9c-ad00-43c3-a816-fcdcc88ff611)

![](https://2172743581-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-La4k4liN--SZ6ay4iod%2F-LcyefyXy8J-D24U0u0N%2F-LcyfT3KFWDeBQ6b0wmq%2FScreen%20Shot%202019-04-21%20at%2012.25.19%20PM.png?alt=media\&token=10dd646f-17ab-41c6-8bd3-eeddf0126fd6)

![](https://2172743581-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-La4k4liN--SZ6ay4iod%2F-LcyefyXy8J-D24U0u0N%2F-LcyfVA3n3_GtifaWqHb%2FScreen%20Shot%202019-04-21%20at%2012.25.28%20PM.png?alt=media\&token=792638e1-2357-4795-a62e-4080e332bf78)

{% hint style="success" %}
Wrapper classes are immutable. Adding a primitive value to a wrapper class variable doesn’t modify the value of the object it refers to. The wrapper class variable is assigned a new object.
{% endhint %}

![](https://2172743581-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-La4k4liN--SZ6ay4iod%2F-LcyefyXy8J-D24U0u0N%2F-LcyfkiCFAjgm9Ww5V_B%2FScreen%20Shot%202019-04-21%20at%2012.26.46%20PM.png?alt=media\&token=81a4fe99-e06f-4845-906d-8565b0d8ca95)

{% hint style="success" %}
Unboxing a wrapper reference variable, which refers to null, will throw a NullPointerException.
{% endhint %}
