1. in Java, variable types other than basic types are called application types. Objects in Java are operated by referencing them.
2. Distinction between classes and objects in the memory:
A. Classes are static and stored inCodeArea;
B. The object is new and located in heap memory (dynamic). Each member variable of the class has different values (except static variables) in different objects ), the method only occupies the memory when executed.
3. regions involved in Java memory allocation:
◆ Register: we areProgramCannot be controlled
◆ Stack: stores basic types of data and object references, but the object itself is not stored in the stack, but stored in the heap.
◆ Heap: stores data generated with new
◆ Static domain: static members defined by static in objects
◆ Constant pool: stores constants.
◆ Non-ram storage: Permanent storage space such as hard disk
4. Memory instance analysis:
A. Main class:
Package YC. test;
Public class t {
Public static voidmain (string [] ARGs ){
Test test = new test ();
Test. SETI (2 );
Test. setj (2 );
System.Out. Println ("add:" + test. Add ());
}
}
B. auxiliary classes:
Package YC. test;
Public class test {
Private int I = 0;
Private Int J = 0;
Public intadd (){
Return I + J;
}
Public intgeti (){
Return I;
}
Public voidseti (int I ){
This. I = I;
}
Public intgetj (){
Return J;
}
Public voidsetj (Int J ){
This. j = J;
}
}
Analysis: Starting from the main function, ① create a reference variable test in the stack memory and set the value to NULL; ② generate an object test in the heap memory, and assign the first address value of the space to the reference variable test; ③ in the stack memory, create a basic data type variable X and assign the value to 2;
④ Assign the I (in heap memory) value of the object referred to by test to X;
⑤ After the assignment is completed, release the X variable in the stack memory before exiting the method and returning to the main function;
⑥ Repeat Step ③ ⑤ to complete the assignment of J of the object indicated by test;
7. Test calls the add method to read and retrieve the I and J Values in the heap memory for computation and complete the output.