Let's not discuss the new Motability strings are immutable that is once a string is created its value 2
can never be changed. 3
For example here is one reference to a String object containing text the next year does this on a new 4
String object that takes ONE TWO THREE FOUR So you know as one is not a fencing a brown you'll string 5
object on the old string object containing that X AB CD remains as is. 6
And we say that it is abandoned making it eligible for garbage collection which will be discussed later 7
so there is really no way for us to change the contents of a string object once created. 8
So there is no a method or anything like that. 9
Good because we say that strings are immutable. 10
So let me say strings are immutable. 11
What we mean is that a string object is immutable a string reference however can be re-assign as many 12
times as we want. 13
In this example the string is created we are the Nuki word but it doesn't matter even if it was a strain 14
when it can. 15
As we know that string literal is also basically a string object so String immutability holds good even 16
for critical assignments next question that you may have is why strings were made immutable. 17
Let's look at a few reasons for this. 18
One is bringing doning if strings are mutable then it wouldn't be possible to share string literals 19
. 20
For example here as one as you are referencing a string object in the string pull not say if strings 21
are mutable and one ablated the string from hello to something else then it could also affect S2 and 22
it would very likely lead to serious issues. 23
As Esther would be expecting the value to be hello and the reason is concurrency that is multi-threading 24
might be reading will be discussed later. 25
But it basically allows multiple threads to perform some actions at the same time. 26
Think of it as a program performing some action. 27
So the problem is similar to Dunning. 28
That is if a string object is mutable and the shared between multiple threads and one thread modifies 29
it then the remaining would get affected without them being offered. 30
So this can lead to lot of bucks one more reason is security and we know that security is very critical 31
for Djala. 32
There are many networking related classes in Java. 33
The big strings are in book using classes with multiple strings can create serious security vulnerabilities 34
for example for reading a file Java there is a class called file input stream runoff it's constrictors 35
takes a file part as a string not if is used at an application fusspot forms user authentication and 36
then uses this class for accessing your file but once the user has authenticated it hacker change the 37
file name inappropriately. 38
If strings were mutable This would allow a hacker to access a file for which he or she may not have 39
permission to access So basically there is a potential for security holes if strings were notable. 40
So these are just few reasons on why strings were made immutable. 41
But the language designers so that's about it. 42
With respect to strength immutability