title: String object is immutable but reference variable is mutable. What does that mean?
body: <p>I was studying Kathy Sierra Java book. I came across one question something like this:</p>
  
  <pre><code>public class A {
      public static void main(String args[]){
          String s1 = "a";
          String s2 = s1;
          //s1=s1+"d";
          System.out.println(s1==s2);
      }
  }
  </code></pre>
  
  <p>output: <code>true</code></p>
  
  <p>Two points I didn't understand here are:</p>
  
  <ol>
  <li>when I uncomment <code>s1 = s1 + "d"</code> output changes to <code>false</code>. Same thing happens if I replace String with wrapper <code>Integer</code> or <code>int</code>.</li>
  <li><p>Again, when I change my code to use <code>StringBuffer</code> like this:</p>
  
  <pre><code>StringBuffer sb = new StringBuffer("a"); 
  StringBuffer sb2 = sb;
  //sb.append("c");
  System.out.println(sb == sb2);
  </code></pre>
  
  <p>now the output doesn't changes i.e. it remains <code>true</code> even if I uncomment the <code>sb.append</code>statement.</p></li>
  </ol>
  
  <p>I can't understand this strange behavior. Can some one explain me.</p>