Java Foundation Classes and Objects of knowledge

Java Foundation Classes and Objects of notes

1, the difference between the member variables and local variables of
the members of a class object variable is defined in the property, he will follow a new object into the memory heap memory.
Local variables are variables defined in the method of the class, method calls after him, following the way into the memory stack memory.

Member variable is not defined after the assignment, the system will default assignment. The default is int type 0, String Null type
must be assigned after the local variables defined in the method.

Life Cycle: because a member variable is to follow the new object out into the heap memory, so it exists as an object exists, if the object is recovered
then disappears with member variables. The local variable is to follow the method, when the method is called push, to create a variable execution time will produce a statement
after a while when the method popped out of the stack, it will disappear.


2, this keyword

What is this key? this refers to the object itself. When the object of which is to call this, this refers to the object.
Which object called, this would indicate which objects


3, the memory of the presentation
java application memory required to run, the application memory is divided into five parts
1, the stack (Stack): the local variable stored inside, and the method of operating an object in the stack memory.
2, the heap (Heap): Any new out of something, there are heap memory. Heap memory variables (member variables) has a default value of
3, method area: storing information .class
4, native method stacks: operating system dependent
5, registers: related cpu

4, the encapsulation
package is one feature of object-oriented
methods is a basic package
class is also a package

Benefits package:
1, increase the reusability of code
2, a way to hide implementation details provide external access to the
3, improves security

5, the program execution flow of
the program execution process described in the Example PERSON:
1, execute the main method (push), wherein execution of the Person new new = P the Person ();
2, open space in the heap memory, and assign memory address 0x1234, followed by members of the default initialization variables (age = 0); assigned to the memory address 0x1234 in the stack Person p variable
3, continue p.setAge (30) statement, then calls setAge (int age) method, 30 assigned to setAge method "age" variable; statement execution this.age = age, the age variable values assigned to the member 30 is variable this.age 30;
setAge () method executes after completion (popped), Back to the main () method, to perform output statement System.out.println (), age age values console print p object.

Released five original articles · won praise 6 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_15139809/article/details/104011650