Learning Java sixth week

1. Memory Architecture

Java program is running, you need to allocate space in memory to improve operational efficiency, space has been divided into different areas, because each one has a specific area of ​​data processing methods and memory management.

Stack memory

· Used to store local variables, when the data used up, less space will be automatically released,

Heap

Arrays and objects, instances established by Bw are stored in the heap memory,

• Each entity has a memory address

· Entities variable has a default initialization value

· Entity is not being used, it will be garbage collected within the time uncertain

Zhejiang heart of this area law enforcement by law area. In material damage

 

 

2. Members and local variables

Fan Figure role

Member variables acting on the entire class.

Variables circumferential portion acts on the function, or statement.

In memory location:

Member variables: in heap memory, because the object exists, exists only in memory,

Local variables: A stack-based memory.

 

3. anonymous object

Anonymous object is a simplified form of objects

Anonymous objects used in two cases

• When an object method is invoked only once

· Anonymous objects can be passed as actual parameters

 

4. Static: static

Usage: is a modifier for modifying member (member variables, member functions)

When the members are static modification, on more than one call, except that the object can be invoked outside, you can also directly call the class name

Static Features:

1, with the loading and load the class,

He says: Static will disappear with the disappearance of class, describe its longest life cycle

2, in preference to the object exists

3, is shared by all objects

4, can be directly invoked by class name

Instance variables and class variables difference:

1, storage location

Class variables as present in the class loading zone method,

With the establishment of an object instance variables exist in the heap memory

2, the life cycle

Class variables longest life cycle, with the disappearance of class disappear

With the disappearance of the life cycle of an instance variable objects disappear

6. Static Precautions

1, static methods can only access static members

Non-static method can access both static can also access non-static

2, static method can not define this, super keyword

Because static precedence over the object exists, it appears this may not be a static method

Static pros and cons

Lee at: shared data objects stored in a separate space, space-saving, is not necessary in each object are stored in a

It can be directly invoked by class name.

Drawbacks: long life cycle

Access appears limitations. (Static is good, can only access static

 

Guess you like

Origin www.cnblogs.com/ywqtro/p/11333896.html