Immutable class in Java | Why immutable class? |How to make a class Immutable by Naren

Опубликовано: 03 Октябрь 2024
на канале: Naren Java Help Line
198
17

This video explains concepts on Immutable Class in Java

What is immutable class?
Immutable means unmodified or unchangeable. Once the immutable class's objects are created, its object values and state cannot be changed.

Example - Primitive objects such as int, long, float, double, Wrapper classes(Integer, Float etc), String class, etc.



How to make a class Immutable?

1. Final class, which is declared as final so that it can't be extended.
2. All fields should be private and final so that direct access to the fields is blocked.
3. No Setters
4. If using a mutable object reference in immutable class, make a deep copy of it and then refer





Your quires:
How to create immutable class in java with mutable object.
use of immutable class in java
real time example of immutable class in java
why string is immutable in java
advantages of immutable class in java
#narenjavahelpline
#corejavainterviewquestions
#java