title: what does obj1 == obj2 actually compare
body: <p>I am studying Overriding <code>hashCode()</code> and <code>equals(Object obj)</code> methods of <code>Object</code> class.</p>
  
  <p>body of <code>equals(Object obj)</code> method in <code>Object</code> class is : </p>
  
  <pre><code>public boolean equals(Object obj) {
      return (this == obj);
  }
  </code></pre>
  
  <p>and <code>hashCode()</code> is <code>native</code> : </p>
  
  <pre><code>public native int hashCode();
  </code></pre>
  
  <p>I have a class <code>Test</code> with overrided <code>equals(Object obj)</code> and <code>hashCoe()</code> : </p>
  
  <pre><code>public class Test {
  
  public static void main(String[] args){
      Test t1 = new Test();
      Test t2 = new Test();
  
      System.out.println("t1 toString() : " + t1.toString());
      System.out.println("t1, Hex value of hashcode : " + Integer.toHexString(t1.hashCode()));
      System.out.println("t2 toString() : " + t2.toString());
      System.out.println("t2, Hex value of hashcode : " + Integer.toHexString(t2.hashCode()));
      System.out.println(t1.equals(t2));
  }
  
  @Override
  public int hashCode() {
      return 999; //hard coded value is just for testing
  }
  
  @Override
  public boolean equals(Object obj) {
      return (this == obj);
  }
  }
  </code></pre>
  
  <p>Output of my Code is :</p>
  
  <pre><code>t1 toString() : demo.Test@3e7
  t1, Hex value of hashcode : 3e7
  t2 toString() : demo.Test@3e7
  t2, Hex value of hashcode : 3e7
  false  //why it is false
  </code></pre>
  
  <p>why <code>equals(Object obj)</code> returns <code>false</code> in this case if both objects <code>toString()</code> returns the same reference ID (<em>hashcode</em>) [I am not sure if it compares hashcode or not].</p>
  
  <p>What does <code>==</code> operator actually compare in case of objects?</p>
  
  <p>in <a href="https://stackoverflow.com/a/7520464/2764279">this</a> answer, answerer said that <em><code>==</code> that is, it returns true if and only if both variables refer to the same object, if their references are one and the same</em>.</p>
  
  <p>How does it know that <em>the variables refer to the same object</em>???</p>