why there is different output for below two codes? : <p>The below program outputs false</p>

<pre><code>    String s1="a";
    String s2="b";
    String s3=s1+s2;
    String s4="ab";

    if(s3==s4)
    {
        System.out.println("true");
    }
    else
    {
        System.out.println("false");
    }
</code></pre>

<p>and this code outputs true</p>

<pre><code>String s3="a"+"b";
  String s4="ab";

  if(s3==s4)
  {
      System.out.println("true");
  }
  else
  {
      System.out.println("false");
  }
</code></pre>

<p>Shouldn't the output in first case be true? As while creating String s4="ab" there is already an object with value "ab" in the string constant pool.</p>
