title: How does string interning work in Java 7+?
body: <p>So, I realize the questions I'm about to ask relate to a topic that has been beaten to death time and time again, however, even after reading all of the answers and documentation I could find, I'm still kind of confused about string interning. Perhaps it's due to my lack of understanding for the JVM; perhaps it's due to the changes introduced in Java 7 depreciating many of the aforementioned answers and documentation. Either way, I'm stuck, and I'm hoping someone can help me understand the concept a bit more clearly...</p>
  
  <pre><code>String a = "text";
  String b = new String("text");
  </code></pre>
  
  <p>In the above example, I understand that two String objects will be created. I also understand that there will be only one char array containing the sequence <code>'t', 'e', 'x', and 't'</code> in memory. </p>
  
  <p>However, where in memory are each of the string objects actually stored? </p>
  
  <p>If what I've read I've read correctly: the referent of variable <code>a</code> will be stored in the constant pool whereas the referent of <code>b</code> will be stored in the heap, right? </p>
  
  <p>If that be the case, I'm confused as to how the intern pool maintains interned strings. Does it keep track of the Strings defined in the constant pool and those that have been manually interned (invoked <code>.intern()</code>) from the heap? Does the JVM create the string objects defined in the constant pool and load them into the intern pool? I'm confused as to how it all works...</p>
  
  <p>Again, sorry for asking such confusing/asinine questions, it's just that I'm relatively new to the structure and inner-workings of the <code>JVM</code> and a lot of it has left my head spinning. Thanks!</p>