Assigning one primitive variable to another vs a reference variable to another
I would like to understand how primitive and object reference variable behaves differently. I have used the below code from OCA/OCP Java SE7 by Kathy Sierra as an example: 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"); } } In the above piece of code,