Java Foundation for its own weaknesses summary 03

Source: Internet
Author: User

First, to talk about the object-oriented thinking

1. What is Object-oriented

1) Object-oriented is object-based, complete a variety of operations, emphasizing the object, the result.
2) process-oriented is based on function, complete various operations, emphasizing the process.
3) Object-oriented is process-oriented.
2. Object-oriented thought characteristics
1) An idea that is more in line with people's thinking habits
2) simplifying complex issues
3) We have become conductors from the executor.
Example: Buy your own computer vs let a friend help you buy a computer
(Process oriented) (object oriented)

Second, class and object

1. A class is a collection of related properties and behaviors, and is an abstract concept.
2, the object is a specific existence of something, is a specific form of representation
Example: Student (Class)
Xiao Ming (object)

Three, the difference between the member variable and the local variable

1. Define the position
Member variables: Outside Methods in class
Local variables: Inside a method in a class, or a parameter on a method
2. Initialize the difference
Member variable: has default initialization value
Local variables: None
3. Storage location:
Member variable: The heap exists with the existence of an object
Local variables: Stack with the existence of the method exists

Iv. Overview of Encapsulation
1、概念隐藏对象的属性和实现细节,仅对外提供公共的访问方式(将属性私有化,并提供公有的访问方法)2、注意

Private is only an embodiment of encapsulation, because classes, functions and so on are actually a package embodiment
3, why to write Getter/setter method (master)
Mentally, because the property is privatized, it can only be used in this class, other classes need to provide a Get method and set method to use
In terms of requirements, set and get methods do not necessarily have to appear, they are independent of each other
And the Set method and the name of the Get method can be random, but the formation of a specification, people through the method to the private property assignment, the formation of a default rule, that is, the method of assigning a value to the property starts with a set, get the property value of the method with get start

V. Instance variables and class variables
 类变量也叫静态变量,也就是在变量前加了static 的变量 实例变量也叫对象变量,即没加 static 的变量 区别在于: 类变量是所有对象共有,其中一个对象将它值改变,其他对象得到的就是改变后的结果;而实例变量则属对象私有,某一个对象将其值改变,不影响其他对象
Six, this keyword (master)

1. Concept (understanding or understanding)
This represents the reference to the object to which the method belongs, which object calls the method, and inside the method there is an implied this that represents the object (who called, which is the representative) (emphasis)
Simply say: Who called, this represents who
2. Application Scenario (function Mastery)
Issues for resolving local variable hidden member variables
Simply put: You can call member variables directly via the This keyword.

VII. code block (master)

1. Overview
The code that is expanded by {} is called a block of code, and a class or method can also be thought of as a block of code, but generally speaking, the code block we refer to is a solitary {}
2. Code block action
Local code block action
Increase efficiency by letting variables disappear as early as possible from memory
Building blocks of code acts as
Define common content in all construction methods in the construction code block, improve code reusability, code block before the construction method execution, but generally not, the final purpose of initializing member variables
Very little work, mostly for interviews.

Viii. Object Initialization process (master)

Person p = new person ();

A: Load the Person.class file into memory (class loader)
B: Open a variable space in the stack memory, give p use
C:new person () will open up space in memory
D: Method into the method area, there is a class name to mark, and, at the same time, the member variable into the heap memory and give the default initialization value
E: Display initialization of the member variable (because the member variable is assigned the public int, age = 34;)
F: If a block of code is constructed, you can assign a value to the member variable in the construction code block
G: Constructor Initialization
H: So far, object initialization is complete.
I: Assign the first address of the heap memory object to the P variable of the stack memory

Nine, Static keyword overview

1. Overview
1) Static can modify member variables and member methods
2) A member of the static modifier has one of the greatest features that can be shared by all objects under the class

2. When to use
When multiple objects share a certain piece of data, we modify the data with static. Example: Chicken feeding
3. Characteristics (Mastery)
1) The static modified content is loaded with the load of the class and takes precedence over the existence of the object
2) can be called directly from the class name
3) shared by all objects under the class

4. Precautions
1) There is no this keyword in the static method, because static is loaded as the class loads. And this is the object creation exists.
2) Static methods can only access static member variables and static member methods a sentence static only access static
3) Static content can be called through an object or by a class name. It is recommended to call the class name

X. Inheritance

1. What is inheritance
1) When the same attributes and behaviors exist in multiple classes, the content is extracted into a single class, so that multiple classes do not need to define properties and behaviors, just inherit.
2) Multiple classes become subclasses or derived classes, and a single class is called a parent class or superclass
3) Let them have a relationship by extends keywords
2. Benefits and characteristics of inheritance
Benefits:
1) Improve the reusability of code
2) to make a relationship between classes and classes is a prerequisite for polymorphism
Characteristics:
1) Only single inheritance is supported in Java, multi-inheritance is not supported
2) Support Multilayer inheritance in Java
3. When to use inheritance
Class B is a kind of the use of inheritance relationship

Comparison of Xi. this and super

1, the difference in concept
Super represents the memory space of the parent class.
This represents a reference to the object to which the method belongs
2. When to use
Use Super when calling the parent class construction method
Use super to differentiate when a member of the same name appears in a child parent class

12. Overriding Override and Reload overload

1. Override the override concept (master)
In a child-parent class relationship, a method that exists in a subclass that is exactly the same as the parent method declaration is called a method override
2. Heavy-duty overload concept
There are multiple methods with the same name in a subclass or child parent class relationship, and a different method of parameter list is called overloading
3, the role of rewriting
Ways to upgrade the parent class

13, child parent inter-class member method considerations (Master)

1. Private methods in the parent class cannot be overwritten (because private ones cannot be inherited, so they are not rewritten)
2. Subclass method access permission is greater than the parent class method access (parent class is public, child class can be public only)

14, sub-parent inter-class structure method characteristics and Precautions (master)

1. Characteristics of construction methods in subclasses (understanding)
The subclass default constructor method accesses the parameterless constructor method of the parent class, with the default statement super () in the subclass construction method, and the default only super () statement with no arguments
Because subclasses have non-private data in the parent class, this initialization is done by the parent class, so the parent class constructor method is called first to initialize the data in the parent class

2. If the parent class has no parameterless constructs, the subclass constructs how to access the parent class construct (master)
1) Call the parent class with a parameter construction method by super (parameter)
2) Pass this (..) Call this class construction method//know the line, generally not, but it is important to note that if the first sentence of all constructors in a class calls this (..), it is an error
3. Will the object of the class be created when the construction method finishes executing?
Not necessarily, the constructor method of a subclass does not create an object when the first row calls the constructor of the parent class

4. Attention
The This () and super () statements in the construction method must be placed in the first row and can only take one

Static blocks of code, blocks of code, construction method execution order (master)
1. Priority level
Static code block, construction code block--construction method
2. Order of execution
Parent class static code block, subclass static code block, parent class construction code block, parent class construction method, subclass construct code block, subclass construction method
3. Static code block action
Initializing static member variables
4. Construct code block function
1. Initializing non-static member variables
2, the common content of all the construction methods extracted, improve the code reuse

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java Foundation for its own weaknesses summary 03

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.