Translate

Tuesday, June 7, 2016

Importance of SCP.

What is SCP?

What is the reason behind of immutability of string object?


SCP stands for String Constant Pool. It is a special memory area.

in our program if a string object is repeatedly required then it is not recommended to create separate object for every requirement because it it creates performance and memory problems.
Instead of creating a separate object for every requirement we have to create only one object and we can reuse the same object for every requirement. So that performance and memory utilization will be improved.
This thing is possible because of SCP, hence the main advantage of SCP is memory utilization and performance will be improved.

But the main problem with SCP is, as several references pointing to the same object, by using one reference if we are trying to change the content then remaining references will be affeacted.
To overcome this problem SUN people implemented string object as immutable i.e. once we create a string object then we can not perform any changes in the existing object, if we are trying to perform any changes with those changes a new object will be created.

Hence SCP is the only reason for immutability of string object.

String s1="hello";

String s2="hello";

s2="bye";


No comments:

Post a Comment