What is the Difference Between Final and Immutable in Java?


If you declare a field or variable final, it means, that you cannot change the object reference stored in it. It will always point to the same object. While you cannot substitute the stored reference with another one, you can modify the referenced object (for example update its fields).

For classes, final means that you cannot create a subclass of it.

Making something final is just a matter of adding a keyword, reaching immutability is a bit more complex.


If an object is immutable, it’s state/value cannot change over time. A good example for this is the String or the BigDecimal class.

BigDecimal for example, has a number of “manipulation” methods like add(), but these methods will not modify the original object, but they will return a new one.

public BigInteger add(BigInteger val) {
        // ...
        return new BigInteger(resultMag, cmp == signum ? 1 : -1);

Making an object immutable is the responsibility of the programmer. It cannot be achieved just by putting there a keyword like in case of final.

Final and immutable

Of course, it is possible for an object to be final and immutable at the same time. A good example for this is the String class.