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: 
> 
> I read that "if String been mutable, a request to load "java.io.Writer" could have been changed to load "mil.vogoon.DiskErasingWriter""
> 
> 
> 

OK. First thing to realize is that this is a **hypothetical** discussion. String is not mutable.

So now imagine this piece of code:

```
public static final String CLASS_NAME = "java.io.Writer";

...

Class<?> clazz = Class.forName(CLASS);

```

What class does this actually load?

If String's were mutable, some nefarious code running in the security sandbox would be able to mutate the *contents* of the String object that CLASS\_NAME refers to. In particular, it could change it from "java.io.Writer" to "mil.vogoon.DiskErasingWriter". The net result is that your application would be tricked into loading the wrong class.

By making String an immutable type (and one or two other things) this attack mechanism is foiled.
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.