Sunday 22 February 2015

Why String is immutable or final in Java

There are several benefits of String because it’s immutable and final.
  • String Pool is possible because String is immutable in java.
  • It increases security because any hacker can’t change its value and it’s used for storing sensitive information such as database username, password etc.
  • Since String is immutable, it’s safe to use in multi-threading and we don’t need any synchronization.
  • Strings are used in java classloader and immutability provides security that correct class is getting loaded by Classloader.
Check this post to get more details why String is immutable in java.

No comments:

Post a Comment