Gitbook:https://joshhug.gitbooks.io/hug61b/content/

  • 2.1
  • this pointer

Q:how does a piece of Java code know how to interpret 01001000?
A:In Java,there are 8 primitive types,each types has different properties.

In addition to setting aside memory, the Java interpreter also creates an entry in an internal table that maps each variable name to the location of the first bit in the “box”.

The exact memory address is below the level of abstraction accessible to us in Java. This is unlike languages like C where you can ask the language for the exact address of a piece of data.

Java does not write anything into the reserved box when a variable is declared. In other words, there are no default values. As a result, the Java compiler prevents you from using a variable until after the box has been filled with bits using the = operator. For this reason, I have avoided showing any bits in the boxes in the figure above.

Reference Variable Declaration Box and Pointer Notation

Just as before, it’s hard to interpret a bunch of bits inside a reference variable, so we’ll create a simplified box notation for reference variable as follows:

  • If an address is all zeros, we will represent it with null.
  • A non-zero address will be represented by an arrow pointing at an object instantiation.

This is also sometimes called “box and pointer” notation.
For the examples from the previous section, we’d have:
CS61B - 图1
CS61B - 图2

  1. Walrus a = new Walrus(1000, 8.3);
  2. Walrus b;
  3. b = a;

CS61B - 图3
According to the GRoE, b will copy exactly the arrow in a and now show an arrow pointing at the same object.