Is there any noticeable difference between
<property name="pwdRetryCount" type="java.lang.Integer">
<column name="pwd_retry_count" />
</property>
and
<property name="pwdRetryCount" type="int">
<column name="pwd_retry_count" />
</property>
In Java, int is a primitive data type while Integer is a Wrapper class. int, being a primitive data type has got less flexibility. We can only store the binary value of an integer in it. Since Integer is a wrapper class for int data type, it gives us more flexibility in storing, converting and manipulating an int data.
The major difference between an Integer and an int is that Integer is a wrapper class whereas int is a primitive data type. An int is a data type that stores 32-bit signed two's complement integer whereas an Integer is a class that wraps a primitive type int in an object.
Use int when possible, and use Integer when needed. Since int is a primitive, it will be faster. Modern JVMs know how to optimize Integer s using auto-boxing, but if you're writing performance critical code, int is the way to go.
Primitive type int needs 4 bytes in Java but, Integer object occupies 16 bytes of memory. Hence, int is comparatively faster than an Integer object. Since, int is a primitive type it is less flexible.
They only have noticeable difference when handling null value.
It is because int
is the primitive data type that cannot assign null to it while java.lang.Integer
is the wrapper class of int
which can accept null .
So , if pwd_retry_count
column is nullable and you use int
to map your entity object , for the record which pwd_retry_count
is null , error occurs as int
cannot store null.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With