title: Java String creation and String constant pool
body: <p>When a String is created using the keyword <em>new</em> it creates a new String object using a constructor that takes a String literal. I'm wondering if the literal get stored in the constant pool before the String constructor is called.</p>
  
  <p>The reason I'm asking is that in "OCA Java SE 7 Programmer I Certification Guide", Mala Gupta writes:</p>
  
  <pre><code>public static void main(String[] args)
  {
      String summer  = new String("Summer");   //Line 1: The code creates a new String object with the value "Summer". This object is not placed in the String constant pool.
      String summer2 = "Summer"                //Line 2: The code creates a new String object with the value "Summer" and places it in the String constant pool.
  }
  </code></pre>
  
  <p>She says on the first line that the String object that is created by <em>new</em> is not stored in the constant pool. This is fine, but what is not clear is if the literal "Summer" that goes in the constructor on the first line is.</p>
  
  <p>On the second line she says that the assignment of "Summer" to <em>summer2</em> stores it in the constant pool, which implies that the literal on the first line was not placed in the pool.</p>
  
  <p><strong>My Question</strong></p>
  
  <ol>
  <li>Line 1: Does the literal "Summer" in the constructor get placed in the constant pool <strong>before the String constructor</strong> is called?</li>
  <li>Line 2: Does "Summer" already exist in the pool at <strong>line 2</strong> or is it inserted at this line?</li>
  <li>Line 2: Is the author wrong when she says that "Summer" is inserted in the pool at <strong>line 2</strong>?</li>
  </ol>