Here is an illustration of the memory map for the following code fragment, which is taken from the PrimitiveVsObjectVariables.java program. This picture shows what Java's memory would look like at the end of the execution of these lines of code. int i; // a primitive variable of type "int" Dimension d; // an object variable of type "Dimension" i = 7; d = new Dimension(4, 5); int j; // another primitive variable of type int Dimension c; // another object variable of type Dimension // The next two statements act very differently!! j = i; // assigning primitive variables (copy values) c = d; // assigning object variables (copy references) // Change the value in the j and c variables j = 107; c.setSize(104, 105); |