I say in terms of Java Serialization:
Although int is a primitive type that only stores the value of the variable (in binary), the Integer object (using ObjectOutputStream ) will store some "metadata" that the Integer object will see when deserialized.
Yes, serialization not only saves the object, but also the state of the object, so if you store it,
private Integer value = 5;
Meaning (lack of a better word) inside Integer and the whole object is saved.
Note added: in order not to store the object / variable, mark the transient , .eg field
transient private Integer value = 5;
Related Resources:
source share