title: Is String Literal Pool a collection of references to the String Object, Or a collection of Objects
body: <p>I am all confused after reading the article on javaranch site by Corey McGlone, The author of  The SCJP Tip Line. named Strings, Literally and the
  SCJP Java 6 Programmer Guide by Kathy Sierra (co-founder of javaranch) and Bert Bates.</p>
  
  <p>I will try to quote what Mr. Corey and Ms Kathy Sierra have quoted about String Literal Pool.</p>
  
  <p><strong>1.</strong> According to Mr Corey McGlone :</p>
  
  <ul>
  <li><p>String Literal Pool is a Collection of references that point to the String Objects.</p></li>
  <li><p><code>String s = "Hello";</code>  (Assume there is No object on the Heap named "Hello"), 
    will create a String object <code>"Hello"</code> on the heap, and will place a reference to this object in the String Literal Pool (Constant Table)</p></li>
  <li><p><code>String a = new String("Bye");</code> (Assume there is No object on the Heap named "Bye", <code>new</code> operator will oblige the JVM to create an object on the Heap.</p></li>
  </ul>
  
  <p>Now the explanation of  <code>"new"</code> operator for the creation of a String and its reference is bit confusing in this article, so I am putting the code and
      explanation from the article itself as it-is below.</p>
  
  <pre><code>public class ImmutableStrings
  {
      public static void main(String[] args)
      {
          String one = "someString";
          String two = new String("someString");
  
          System.out.println(one.equals(two));
          System.out.println(one == two);
      }
  }
  </code></pre>
  
  <p>In this case, we actually end up with a slightly different behavior because of the keyword <code>"new."</code> 
  In such a case, references to the two String literals are still put into the constant table (the String Literal Pool),
  but, when you come to the keyword <code>"new,"</code> the JVM is obliged to create a new String object at run-time, 
  rather than using the one from the constant table.</p>
  
  <p>Here is the diagram explaining it..</p>
  
  <p><img src="https://i.stack.imgur.com/8FAKX.jpg" alt="enter image description here"></p>
  
  <p><strong>So does it mean, that String Literal Pool too has a reference to this Object ?</strong></p>
  
  <p>Here is the link to the Article by Corey McGlone</p>
  
  <p><a href="http://www.javaranch.com/journal/200409/Journal200409.jsp#a1" rel="noreferrer">http://www.javaranch.com/journal/200409/Journal200409.jsp#a1</a></p>
  
  <p><strong>2.</strong> According to Kathy Sierra and Bert Bates in SCJP book:</p>
  
  <ul>
  <li><p>To make Java more memory efficient, the JVM set aside a special area of memory called the "String constant pool", when the compiler
  encounters a String Literal, it checks the pool to see if an identical String already exists or not. If not then it creates a 
  new String Literal Object. </p></li>
  <li><p><code>String s = "abc";</code>  // Creates one String object and one reference variable.... </p>
  
  <p>that's fine, but then I was confused by this statement:</p></li>
  <li><p><code>String s = new String("abc")</code> // Creates two objects, and one reference variable.</p>
  
  <p>It says in the book that.... a new String object in normal(non-pool) memory , and "s" will refer to it... whereas
  an additional literal "abc" will be placed in the pool.</p>
  
  <p>The above lines in the book collide with the one in the article by Corey McGlone.</p>
  
  <ul>
  <li><p>If String Literal Pool is a collection of references to the String object as mentioned by Corey McGlone, then why wil the literal object "abc" be placed in the pool (as mentioned in the book)? </p></li>
  <li><p>And where does this String Literal Pool reside?</p></li>
  </ul></li>
  </ul>
  
  <p>Please clear this doubt, though it won't matter too much while writing a code, but is very important from the aspect of memory management, and
  thats the reason I want to clear this funda.</p>