When designing a class, to make it immutable or not is a design choice and usually a tradeoff. The classes String and Integer were made immutable for many reasons including security.
A class like java.util.Random is all about managing some state, so it has to be mutable.
A class like java.awt.Rectangle is mutable, which has the advantage of saving memory management costs when you modify one rather than create a new one, but unfortunately it means that when a Rectangle instance that's shared (e.g. by two different window objects), changing it for one of them will change it out from under the others, causing unhappy surprises. Modern garbage collectors are very efficient [I hear they're more efficient than C's malloc()
and free()
] so mutability may not actually save memory management overhead, certainly not if you often have to copy objects to protect against accidental shared changes.
You can freely share an immutable object without worrying about it changing out from under you.