title: Is String Pool really empty initially as mentioned in the Javadoc of String.intern() method?
body: <p>Below is the Javadoc comment for String.intern() method:  </p>
  
  <p>*Returns a canonical representation for the string object.  </p>
  
  <p>A pool of strings, <strong>initially empty</strong>, is maintained privately by the class String.  </p>
  
  <p>When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equals(Object) method, then the string from the pool is returned. Otherwise, this String object is added to the pool and a reference to this String object is returned.  </p>
  
  <p>It follows that for any two strings s and t, s.intern() == t.intern() is true if and only if s.equals(t) is true.  </p>
  
  <p>All literal strings and string-valued constant expressions are interned. String literals are defined in section 3.10.5 of the The Java™ Language Specification.”  </p>
  
  <p><strong>But I think something changed jdk-8u102 onwards.</strong>  </p>
  
  <p>Check below example:  </p>
  
  <pre><code>public class Test1 {
      public static void main(String[] args) {
          String s1 = new String(new char[]{'J', 'a', 'v', 'a'});
          String s2 = s1.intern(); 
          System.out.println(s1 == s2);
      }
  }
  </code></pre>
  
  <p><em>If you run above program in JDK 7u80 (Last stable release of JDK 7) and JDK 8 till 8u101, then output is:</em><br>
  <strong>true</strong>  </p>
  
  <p><em>But if you run above program in JDK 8u102 onwards and in JDK 9 &amp; JDK 10, then output is:</em><br>
  <strong>false</strong>  </p>
  
  <p><strong>Why the intern() method started behaving differently JDK 8u102 onwards?</strong>  </p>
  
  <p>I checked the release notes and Javadoc comments but couldn’t find anything about changes related to intern() method in JDK 8u102.  </p>
  
  <p>I checked blogs and other websites but no luck.  </p>
  
  <p>But when I tried with some other string, then there was no change in the output:   </p>
  
  <pre><code>public class Test2 {
      public static void main(String[] args) {
          String s3 = new String(new char[]{'U', 'd', 'a', 'y', 'a', 'n'});
          String s4 = s3.intern();
          System.out.println(s3 == s4);
      }
  }
  </code></pre>
  
  <p><em>Above program always prints <strong>true</strong> in JDK 7, JDK 8, JDK 9 and JDK 10.</em>  </p>
  
  <p>This behaviour is possible only when, “Java” is referred by the String Pool table before Test1 class is loaded.<br>
  s1 refers to String object “Java” on the HEAP and s1.intern() returns the reference of String Pool object (as “Java” is already referred by the String Pool).<br>
  That is why s1 == s2 returns false.  </p>
  
  <p>But when Test2 class is loaded, “Udayan” is NOT referred by the String Pool table.<br>
  s3 refers to String object “Udayan” on the HEAP and s3.intern() adds String object referred by s3 to String Pool and returns the same reference. This means s3 and s4 refer to the same object.<br>
  That is why s3 == s4 returns true.  </p>
  
  <p>If my observation is correct, then this means <strong>pool of Strings is NOT empty initially.</strong><br>
  String pool initially contains “Java”, “java”, “Oracle” and other String objects.  </p>
  
  <p>Can anyone please confirm this? </p>