------Java Training, Android training, iOS training,. NET training, look forward to communicating with you! -------
1. An object-oriented idea that encapsulates functionality into objects, emphasizing functional objects
2. Object-oriented three features: encapsulation, inheritance, polymorphism. Find objects, build objects, use objects, maintain relationships between objects
3. Relationships between classes and objects: class is the description of things in real life, is the specific abstract
Objects are real individuals of this kind of thing, the object is the entity that corresponds to Java in heap memory with new
A property corresponds to a variable in a class that behaves as a function (method) in a class, and collectively becomes a member of a class (member variable, member method)
How objects are used: objects. Object Members
Car c = new car (); C is a class-type variable, and a class-type variable points to an object
4. member variables and local variables
The scope of the action is different: the member variable acts on the whole class, the local variable acts in the function, or in the statement;
The memory location is different: the member variable is in the heap memory, because the object exists and the local variable is in the stack memory.
5. Anonymous object: New class Name (). method; such as new Car.run ();
How to use: You can use an anonymous object when you use it only once for the object. Use of waste to become garbage
Anonymous objects can be passed as actual parameters
6. Encapsulates the properties and implementation details of encapsulation hidden objects, providing public access only to the outside
Benefits: Isolate changes for ease of use improve reusability for increased security,
Encapsulation principle: To hide content that does not need to be provided externally, to encapsulate attributes, and to provide public access to them externally;
7. Constructors
Feature: function name is same as class name do not define return value type can not write return statement
Once the object is established, the corresponding constructor is called. constructor is used to initialize the object
When a class does not have a constructor defined, the system defaults to a constructor that adds an empty argument to the class.
When a constructor is defined in a class, the default constructor is gone. Multiple constructors exist in the form of overloads
The constructor is compared to the general function: the constructor runs on object one, initializes the object, and the general function is the object invocation, which adds functionality to the object.
An object is established, the constructor runs only once, and the general function can be called multiple times by the object
8: Construct the code block {...}......}
Function: Initializes an object to run as soon as it is established, and takes precedence over the execution of the constructor
The difference: Constructing a block of code is a unified initialization of all objects, and constructors are initialized to the corresponding function.
9. This represents the reference to the object to which the function is located (which object calls the function, which object this represents)
Static is a modifier that modifies member variables, member functions
When a member is statically modified, it can be called directly by the class name, in addition to being called by the object. Class name. static member Person.country
Features: 1. Load as the class is loaded and disappears as the class disappears, long life cycle (normal member variables exist with object creation, called instance variables)
2. Precedence over object existence 3. Shared by all objects 4 can be called by the class name
Instance variables differ from class variables:
1. Class variables are placed in the memory of the shared area, also known as the method area, data area; instance variables exist in heap memory as the object is established
2. Class variables have the longest life cycle and disappear as the class disappears; the instance variable life cycle disappears as the object disappears
Static usage Considerations: Static methods can only access static members; The This super keyword cannot be defined in a static method because it takes precedence over the existence of an object; The main function is static
11. The main function is a special function, which can be called by the JVM as the entry of the program.
Public represents the maximum number of access permissions for the function
Static represents the main function with the loading of the class already exists
Main is not a keyword, it is a special word that can be identified by the JVM
argument is an array of type string
The main function is fixed format, the variable name args can be arbitrarily written, formerly known as arguments
When the JVM calls the main function, it passes in the new string[0]
12. When are static variables defined? When shared data appears in an object
When do I define a static method? When no non-static data is accessed inside the feature
A tool class composed of static methods, which can force the class to not create objects, can be done by privatizing the constructor.
13. Help document making Javadoc. The Java specification is done through documentation comments.
/**
This is a XXX tool class
@author Millet
@version V1
*/
/**
@param ABC
@return
*/
The class that writes the document must be public or protected decorated
A default constructor in a class that has the same permissions as the owning class
14. Static code blocks execute only once, as classes are loaded. Used to initialize a class and take precedence over other components
static {....... }
15. Initialization of the object:
1. First locate the class file and load it into memory
2. Execute a static block of code in a class
3. Space in heap memory, assigning memory addresses to Objects
4. Establish the unique properties of the object in heap memory and initialize it by default
5. Initialize various assignments for displaying properties
6. Constructing a code block class on an object
7. Initialize the object with the corresponding constructor function
8. Assigning the memory address of an object to a variable in the stack memory
16. Design Patterns A total of 23 ways to solve a certain type of problem the most effective way
Singleton design pattern: Solve altogether class in memory only exists altogether object
Lazy: An object is initialized when the method is called. Single class into memory, object does not exist, object is established only when the Get method is called
A hungry Man: Single class in memory, you have created the object
class Single // a hungry man type { private single () {} private StaticNew single (); Public Static Single getinstance () { return s; }}
class Single // lazy-type { private single () {} private Staticnull; Public Static Single getinstance () { if(s==null) new single (); return s; }}
17. Inheritance: Improved reusability of code
Having a relationship between classes and classes, with polymorphic properties
A class has a relationship with a class before it can be inherited.
Java only supports single inheritance, multi-inheritance is easy to bring security risks, when more than one parent class defined the same function, the function content is not the same, the subclass object is not sure which one to run
Java retains this mechanism and is represented by another form of representation called multiple implementations.
Java supports multiple layers of inheritance.
18. After the child parent class appears, the characteristics of the class member
1. Variable if a non-private member variable with the same name appears in the subclass, the subclass has to access the variable in the original, there is this; Access the variables in the parent class, using super. This represents a reference to an original object, and super represents a reference to the parent class object
2. Function when a subclass has a function that is identical to the parent class, the subclass object calls the function, and the function of the subclass is run, and the parent class's function is overwritten (overridden)
Overriding feature: The subclass overrides the parent class, and must ensure that the child class's member permissions are greater than the corresponding parent class permissions, otherwise the compilation fails; static can only overwrite static
Overloading only looks at the argument list of the function with the same name, overriding: The Child parent class function is exactly the same
19. Characteristics of constructors in child parent class:
Instantiation process of subclasses
All constructors of a subclass, by default, access the constructor of the parent's hollow argument.
Because the first line of each constructor of a subclass has an implicit super (); When there is no empty argument constructor in the parent class, the subclass must manually specify the constructor to access the parent class by using the Super form
The first row of a subclass's constructor can also specify the this statement to access a constructor in this class, only one constructor in the subclass accesses the constructor in the parent class
20.final keywords
1. You can modify classes, functions, variables
2. A class that is final modified cannot be inherited. Inheritance has a drawback: it destroys encapsulation
3. The final modified method cannot be overridden
4. The final modified variable is a constant and can only be assigned once. You can either modify the member variable or modify the local variable
Application: When describing things, the values of some data are fixed, and in order to enhance the reading, the values are named and final decorated. As a constant, write the specification all uppercase letters, the words between the underline connection
public static final Double PI = 3.14;
5. When the inner class is defined at a local location in the class, only the local, final decorated local variables can be accessed
21. Characteristics of Abstract classes:
1. Abstract method must be in abstract class 2. Abstract methods and abstract classes must be modified by the abstract 3. Abstract classes cannot create objects with new
4. A method in an abstract class must be used to create a subclass object after all its abstract methods have been replicated by the subclass. If a subclass overrides only a subset of the abstract methods, then the subclass is an abstract class
abstract int power ();
An abstract class cannot be instantiated.
Abstract methods can not be defined in abstract classes, but do not allow objects to be created
22. Template method: When defining a function, part of the function is determined, but part of it is indeterminate, the identified part is used in the indeterminate part, then the indeterminate part is exposed,
Done by subclasses of the class.
23. Interface interface is a special abstract class that, when the methods in an abstract class are abstract, the class can be represented by an interface
The member modifiers in the interface are fixed
Member constants: public static final
Member Method: Public abstract
The interface is not available to create objects and requires a quilt class implementation. The abstract method of the sub-class docking port can be instantiated only after it has been overwritten. Implements
Interfaces can be implemented in many classes, a class can inherit only one class in Java, but multiple interfaces can be implemented at the same time
There can be an inheritance relationship between an interface and an interface
24. Polymorphism: Multiple forms of existence for a certain class of things
The manifestation of polymorphism: the reference of the parent class points to its own subclass object, and the reference of the parent class can accept its own child class object
The benefits of polymorphism: greatly improving the scalability of the program
The premise of polymorphism: it must be a relationship between a class and a class: inheritance, or implementation; presence overrides
The disadvantage of polymorphism: increased extensibility, but only the members of the parent class can be accessed using a reference to the parent class
When a parent class reference points to its own child class object, you can force the reference to be converted to a subclass type.
Keyword instanceof: Object name instanceof The class name is used to determine whether the object belongs to the class
------Java Training, Android training, iOS training,. NET training, look forward to communicating with you! -------
Java Object-oriented notes