Java Basic Knowledge Memo

Source: Internet
Author: User

1.java Memory allocation

A. Register Cup--not currently involved

B. Local method Stack--The virtual machine calls Windows functions, such as creating a folder

C. Method area-store the. class file, which is responsible for storing the method

D. Stack--Responsible for running the method (the runtime copies a copy from the method area to the stack)

E. Heap-Create and store objects (new objects)

2. Stack and heap differences

A. Storage content stacks-method Heap-objects

B. Default stack-No default heap-there are default values (so member variables do not need to be assigned, local variables must be assigned values)

C. Life cycle Stack-method execution Complete Popup heap-object is used, waiting for virtual machine to be recycled (Heap > Stack)

3. Classes and objects

  A. Class-Class is a collection of entities with certain common characteristics, which is an abstract concept, such as human

B. Object-The so-called object is the real-world entity, object and entity is one by one corresponding, that is, every entity in the real world is an object, it is a concrete concept.

  A class is a collection of objects that are instances of a class (people are classes, Zhang San are specific objects)

4. The difference between a member variable and a local variable

A. Defining locations different member variables-class local variables-Methods

B. Default value member variable-the following class is stored in the heap with default values; Local variables-follow method stack, no default value, use must be manually assigned

5. Overloading and rewriting of methods

Overrides-also known as overrides-for inheritance, subclasses override or extend the parent class method, the method name, and the return value type must be the same

Overloading-method overloading is a means for a class to handle different types of data in a uniform manner. Multiple functions with the same name exist at the same time, with different parameter number/type (for example, constructor).

6. Code block

A. Local code block-Basic No, limit the life cycle of local variables

B. Static code block-the object in the class is run once, not later, as long as the class is in memory and runs

C. Building code blocks-every new object in a class runs

Run sequential static code blocks > construct code blocks > Construction Methods

7. Inheritance

Inheritance Benefits:
Fewer code, less write volume
Subclasses can extend the functionality of the parent class
Inheritance causes the class to relate to the class, and with this relationship leads to the third characteristic polymorphism of the object-oriented

Precautions:
Single inheritance, multi-layer inheritance; A class can inherit only one parent class (a child can have only one father, a father can have multiple children)

You can inherit only member variables and methods that are not private to the parent class (if the parent class is private, the subclass does not know)

Relationship of child-parent class member variables after inheritance:

The nearest use principle, if subclasses have, use their own, do not look for the parent class

  

Summarizes the characteristics of the subclass parent constructor Method:
1. Subclass all constructor methods The first line is super (), calling the parent class Null argument construction method
2. If there is no null argument construction method in the parent class, the subclass construction method must write super Pass parameters, otherwise the compilation fails
3. Subclass construction Method Write this or super, select one, ensure that the subclass can indirectly or directly access the parent class null argument constructs

Subclass all construction methods must have access to the parent class construction method Anyway, because the child class needs to see how the parent class member is initialized when the

  

8. polymorphic

Polymorphic Details:

Quick Memory Method: Fu f = new Zi ();
Except for non-static member methods, the compile run looks to the left
Only non-static member method, compile look left, run look right


Why compile look Left
Javac Compilation tool, source files compiled into JVM-recognized class files
Check for syntax errors
Fu f = new Zi ();
F.x can only check Fu this class, check the = right object (object establishment is the thing of the run time)

Why only non-static member methods, run is subclass rewrite
All the other runs are the parent class--the design idea is to extend the subclass
Fu f = new Zi ();
F.xxxx

  

   

Java Basic Knowledge Memo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.