Question:What are the advantages of immutability in java?


1) Immutable objects are automatically thread-safe, the overhead caused due to use of synchronisation is 
2) Once created the state of the immutable object can not be changed so there is no possibility of them 
getting into an inconsistent state.
3) The references to the immutable objects can be easily shared or cached without having to copy or clone 
them as there state can not be changed ever after construction.
 4) The best use of the immutable objects is as the keys of a map.

asked Sep 13, 2013 in Java Interview Questions by ashish singh
edited Sep 12, 2013
0 votes

2 Answers

0 votes


public final class FinalPersonClass {
private final String name;
private final int age;
public FinalPersonClass(final String name, final int age) {
super(); = name;
this.age = age;
public int getAge() {
return age;
public String getName() {
return name;
answered Sep 13, 2013 by rajesh
edited Sep 12, 2013