Strange 'null' string as value and makes the String object not empty, why?
<p>Try this code, and you will see the output, the code uses two String one in a class and another in a variable, the output of the both usages is very different and strange, why and how can I solve it?</p>

<pre><code>---------With class...
null
null
null hello
---------With variable...
null

 hello
</code></pre>

<p>Setting null to the name becomes into this value for the String, why? I need the name to be null and not 'null'.</p>

<p>Thanks by your help.</p>

<pre><code>//'main' method must be in a class 'Rextester'.
//Compiler version 1.8.0_72

import java.util.*;
import java.lang.*;

class Car {
   private String name;

   public void setName( String name ) { 
       if (this.validateName( name )) 
          this.name = name; 
   }

   public String getName() { return name; }

   public boolean validateName(String name) { 
      return name != null &amp;&amp; name.trim() != ""; 
   }

   public boolean validate()
   { return this.validateName( this.name ); }
}

class Rextester
{  
    public static void main(String args[])
    {

        System.out.println( "---------With class..." );
        Car t = new Car();

        t.setName(null);
        System.out.println( t.getName() );

        t.setName("");
        System.out.println( t.getName() );

        t.setName(t.getName() + " hello" );
        System.out.println( t.getName() );     

        System.out.println( "---------With variable..." );

        String nullString = new String();

        nullString = null;
        System.out.println( nullString );

        nullString = "";
        System.out.println( nullString );

        nullString = nullString + " hello";
        System.out.println( nullString );
    }
}
</code></pre>