2. Data types in java
Java has two categories of data types: primitive and reference.
Primitive types are the basic types that store values directly in
memory, such as int, char, boolean, and so on. Reference types
are the types that store references to objects in memory, such
as String, Integer, Boolean, and so on. Objects are instances of
classes that have attributes and methods. Reference types are
also known as wrapper classes, because they wrap primitive
values in objects.
3. Autoboxing in java
The automatic conversion of primitive data types into its
equivalent Wrapper type is known as autoboxing.Autoboxing is
the process of converting a primitive value to a corresponding
reference object, such as int to Integer.For example, if you have
a list of integers, you can use autoboxing to add primitive values
to the list.
5. Unboxing in java
The automatic conversion of wrapper class type into
corresponding primitive type, is known as Unboxing. Unboxing is
the process of converting a reference object to a corresponding
primitive value, such as Integer to int. For example, if you have a
list of integers, you can use unboxing to get primitive values from
the list. Autoboxing and unboxing are features that allow the
compiler to automatically convert between primitive and
reference types, without using explicit cast operators.
7. Advantages of autoboxing and unboxing
More concise and more readable code
No Need to perform any typecasting explicitly
Make your code more flexible and interoperable
Collections Framework Integration like map,list.
We can assign “null” to an object of a wrapper class
8. Disadvantages of autoboxing and unboxing
Performance overhead
More memory consumption
Slow down your program
Increase the garbage collection activity
Can cause unexpected errors such as null pointer
exception,arithmetic exceptions,and class cast
exceptions