title: Why java execution order is different each time & Value comparison is wrong
body: <p>I am having doubt on System.err.print() execution control. The order in which statements are printed is differs for each execution.   I do have 2 questions.</p>
  
  <p>Following is the code</p>
  
  <pre><code>public class AutoBoxingProblems {
  
      public static void main(String[] args) {
  
          problem1();
  
          problem2();
  
     }
  
      private static void problem2() {
          System.out.println("Problem2");
          // Be very careful, Even values are same but two different objects, this will give you equal
          Integer i1 = 100;
          Integer i2 = 100;
  
          if (i1 == i2) {
              System.err.println("i1 and i2 is equal  ==&gt; Problem2");
          } else {
              System.err.println("i1 and i2 is not equal  ==&gt; Problem2");
          }
      }
  
      private static void problem1() {
          System.out.println("Problem1");
          // Be very careful, Even values are same, this will give you unequal
          Integer i1 = 260;
          Integer i2 = 260;
          if (i1 == i2) {
              System.err.println("i1 and i2 is equal  ==&gt; Problem1");
          } else {
              System.err.println("i1 and i2 is not equal  ==&gt; Problem1");
          }
      }
  }
  
  
  
    //Output
      //Some times
      Problem1
      Problem2               
      i1 and i2 is not equal ==&gt; Problem1 
      i1 and i2 is equal ==&gt; Problem2
  
      //Some times
      Problem1
     i1 and i2 is not equal ==&gt; Problem1 
     i1 and i2 is equal ==&gt; Problem2
     Problem2
  </code></pre>
  
  <p><strong>Question1:</strong>  Why in each execution,  print statements order differs?</p>
  
  <p><strong>Question2:</strong>  Why one method prints the values are equal and other method says not equal? (To compare values, we should use 'equals' only. But why '==' operator behaves weird?)</p>