title: How != and == operators work on Integers in Java?
body: <p>The following code seemed really confusing to me since it provided two different outputs.The code was tested on jdk 1.7.</p>
  
  <pre><code>public class NotEq {
  
  public static void main(String[] args) {
  
      ver1();
      System.out.println();
      ver2();
  }
  
  public static void ver1() {
      Integer a = 128;
      Integer b = 128;
  
      if (a == b) {
          System.out.println("Equal Object");
      }
  
      if (a != b) {
          System.out.println("Different objects");
      }
  
      if (a.equals(b)) {
          System.out.println("Meaningfully equal.");
      }
  }
  
  public static void ver2() {
      Integer i1 = 127;
      Integer i2 = 127;
      if (i1 == i2) {
          System.out.println("Equal Object");
      }
  
      if (i1 != i2){
          System.out.println("Different objects");
      }
      if (i1.equals(i2)){
          System.out.println("Meaningfully equal");
      }
  }
  
  }
  </code></pre>
  
  <p><em><strong>Output:</em></strong></p>
  
  <blockquote>
    <p>[ver1 output]<br>
    Different objects<br>
    Meaningfully equal.</p>
    
    <p>[ver2 output]<br>
    Equal Object<br>
    Meaningfully equal</p>
  </blockquote>
  
  <p>Why the == and != testing produces different results for ver1() and ver2() for same number much less than the Integer.MAX_VALUE? Can it be concluded that == checking for numbers greater than 127 (for wrapper classes like Integer as shown in the code) is totally waste of time?</p>