How does Java associate a variable name with a location in memory?
My first thought about this is there must be a static table that is used for all variable names which associates it with either it's value or a location to it's value. Does it exist and is there a formal name for this table?
解决方案
The value of variable of primitive type is some number and value of variable of reference type is a reference (usually an memory address).
Now the question is: where is stored value of given variable. It depends on the the kind of variable - there are local variables, instance variables (fields) and class variables (static fields).
Names of locals are resolved during compilation. Each variable becomes simply i-th variable in method and it will be stored as i-th variable in stack frame of some method call.
For instance variables it will be different. Field names are always present in bytecode (but will generally not be present in machine code generated by JIT compiler). All objects of given class have the same layout, so class can store offset of given field - distance from beginning of the object. Interpreter can read the address of object and add offset to calculate where is variable stored.
Class variables are similar to instance variables, but simpler. In this case, class stores both names and values of its variables.