Question: I know that Strings are immutable.

Then, what is the difference between:

```
String name ="Name";
final String name ="Name";

```

Why do we use `final` in this context? Because String is already immutable there seems to be no need. Second related question, why are String's `immutable`?. Other Data Types like int, boolean are not. If String is immutable does that make it thread-safe? I read that **"if String been mutable, a request to load "java.io.Writer" could have been changed to load "mil.vogoon.DiskErasingWriter""** `means` ?

Answer: 
Like William said :

> 
> final means you cannot assign the variable a new value.
> 
> 
> 

In addition, if you play with anonymous inner class like that :

```
final String mystring = "Hello";
button.addClickHandler(new ClickHandler() {
    void click() {
        System.out.println(mystring);
    }
});

```

The `mystring` object **must** be final.
The other points have already been answered here, but you are still looking for an explaination to that quote you found:

> 
> if String been mutable, a request to load "java.io.Writer" could have
>  been changed to load "mil.vogoon.DiskErasingWriter"
> 
> 
> 

For reference, this appears to be from a different SO answer which is somewhat short and leaves out detail.

In general, if you write a public class that accepts mutable objects and stores them, or that returns a mutable object it is storing, the calling code can change that object from under the feet of that class.

For an example. Disclaimer: I don't know much about ClassLoader, so this is just for the sake of illustrating the problem. ClassLoader has a function `loadClass(String name)`. Imagine that method first checks if the class of that name is valid or trusted, and then loads it. Now if String was mutable, the calling code could change the class name from under the class loader's feet after it had already checked the class, and thus circumvent security measures.

Of course, if String was mutable, one could hope the implementation of ClassLoader would first make a *defensive copy* of the String. That way, the calling code has no chance of circumventing the security since it has no way to modify the contents of the *copy*. This is a general rule: Don't let calling code have any handle on mutable internal data of your class.

So String does *not* need to be immutable to ensure safe class loading. However, with immutable objects it is easier to ensure this kind of security, since they simply can't be changed from under you.