new String() is an expression that creates String ... and a String unchanged, regardless of how it is created.
(the question of whether new String() volatile or not is pointless. This is program code, not value. But I suppose this is not what you really meant.)
If I create a string object since String c = ""; - an empty entry created in the pool?
Yes; those. an entry is created for an empty line. There is nothing special about an empty String .
(To be pedantic, the pool entry for "" is created long before your code is executed. In fact, it is created when your code is loaded ... or perhaps even earlier than that.)
So, I wanted to know if the new heap object is immutable ...
Yes it is. But immutability is a fundamental property of String objects. All String objects.
You see that the String API simply does not provide any methods for modifying a String . Therefore (except for some dangerous and silly 1 tricks using reflection) you cannot mutate String .
and if so, what was the purpose ?.
The reason Java String designed as an immutable class is simplicity. This makes it easier to write the right programs and read / explain other people's code if the main class of strings provides an immutable interface. (Or, at least, this is the rationale for this design decision, as I understand it).
Following the answer, I understand that other references to the same variable are one of the reasons. Please let me know if I understand this correctly.
No. This is more fundamental than that. It's just that all String objects are immutable. Understanding this does not require complicated special argumentation. It just โ is <lt ;.
For the record, if you want to use a mutable "string" object in Java, you can use StringBuilder or StringBuffer . But these are different types for String.
1 - The reason these IMO tricks are dangerous and stupid is because they affect the values โโof strings that are potentially shared by other parts of your application through the string pool. This can lead to chaos ... because the next guy supporting your code has little chance of tracking.