Consider the following example.
String str = new String();
str = \"Hello\";
System.out.println(str); //Prints Hello
str = \"Help!\";
System.out.println(s
Here immutability means that instance can point to other reference but the original content of the string would not be modified at the original reference. Let me explain by first example given by you. First str is pointing to "Hello" ,its Ok upto this. Second time its pointing to "Help!". Here str started pointing to "Help!" and the reference of "Hello" string is lost and we can not get that back.
In fact when str would try to modify the existing content,then another new string will be generated and str will start to point at that reference. So we see that string at original reference is not modified but that is safe at its reference and instance of object started pointing at different reference so immutability is conserve.