Wednesday, May 14, 2008

Java Strings Immutable

Many modern languages (like java) employ “the immutable object” paradigm, which solves a lot of problems including the
  1. Memory conservation
  2. Addressing concurrency concerns
  3. Cache localization
Memory Conservation - A pool of string objects ( constant ) is maintained with references pointing to the constant objects. Instead of each variable having new String object. Re usability leads to lesser memory usage.

Concurrency Concerns - if you change any string need to consider that more than one references may be pointing to same string , so if you will change that string all references must also be updated ( thats tough ) so a new object for changed string will be created and only that particular reference will be point to that new object hence actual object will never change.

I am not sure about cache localization ??

No comments: