You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
java uses primitive types ( int, float, double, char ) to hold the basic data types.
using objects for these values would add an unacceptable overhead to even the simplest of calculations.
despite the performance benefit offered by the primitives, there are times when you will need an object
representation.
E.x:
i. you cannot pass a primitive type by reference to a method.
ii. many standard data structures implemented by java operate on objects, you can't use primitives.
To handle this kind of situation java provides type wrappers, which are classes that encapsulate a primitive
type within an object.
Java provides immutable wrapper classes for all primitive types:
Since wrapper Boolean is used inside if condition, it is auto unboxed to primitives and the condition is checked.
Auto unboxing happens automatically during conditional expression of while, for, or do while loops.
warning: Although using wrapper types is completely fine, it adds an overhead of auto boxing and unboxing, so it is better to use
primitives and only use wrappers where the object representation of a primitive type is required.