title: What is the difference between Heap memory and string constant pool in java
body: <p>In Java</p>
  
  <ol>
  <li>Object created using <strong>new operator</strong> will be stored in the <strong>heap
  memory</strong>.</li>
  <li>The object created using <strong>string literal</strong> is stored in
  the <strong>string constant pool</strong></li>
  </ol>
  
  <p>I'm running the below code to check the hashcode.</p>
  
  <pre><code>    String nameOne = "Deepak";
      String nameTwo = new String("Deepak");
      System.out.println("nameOne address    -- "+nameOne.hashCode());
      System.out.println("nameTwo address    -- "+nameTwo.hashCode());
  </code></pre>
  
  <p>output of the code is</p>
  
  <pre><code>nameOne address    -- 2043177526
  nameTwo address    -- 2043177526
  </code></pre>
  
  <p>Both objects are created using new operator and string literal and stored in different places heap memory and string constant pool accordingly. Then how the memory address is same.</p>
  
  <p>Please explain about the concept, if i'm wrong</p>