title: Assigning one primitive variable to another vs a reference variable to another
body: <p>I would like to understand how primitive and object reference variable behaves differently. I have used the below code from <em>OCA/OCP Java SE7</em> by Kathy Sierra as an example:</p>
  
  <pre><code>public class VariableTesting {
      public static void main(String[] args) {
          int a = 10;
          System.out.println("a= " + a);
  
          int b = a;
          b = 30;
          System.out.println("a= " + a + " after change it to b and b is " + b);
  
          Dimension a1 = new Dimension(5, 10);
          System.out.println("a1.height = " + a1.height);
  
          Dimension b1 = a1;
          b1.height = 30;
  
          System.out.println("a1.height= " + a1.height + " after change to b1");
      }
  }
  </code></pre>
  
  <p>In the above piece of code, I'm getting the value of <code>a = 10;</code> before and after changing the value of <code>b</code>.</p>
  
  <p>The output for the primitive variable case is:</p>
  
  <pre><code>a = 10
  a = 10 after change it to b and b is 30
  </code></pre>
  
  <p>However, in object reference variable I'm getting a different value once I change the value of <code>b1.height = 30;</code></p>
  
  <p>The output for the reference variable case is:</p>
  
  <pre><code>a1.height = 10
  a1.height = 30 after change to b1
  </code></pre>
  
  <p>It is mentioned in the book that in both case the bit pattern is copied and a new copy is placed. If this is true, then why we are getting different behavior?</p>