1. Review
1. Differences between Classes and Objects
2.UML(uniform makeup language)
3. Method areas store static variables, constants (static final modifications)
4. Stored objects in heap memory
5. Stack Storage Variables
6.this() can be used to construct the first line of the method
7.static static statement blocks (static statement blocks are loaded when classes are first used in the JVM), and can also modify variables and methods
8. Design patterns are reusable solutions that can be grouped into four categories
9. Class Inheritance (Single Inheritance)
10. Method override (same modifier, same method name, same parameter)
11. Polymorphism, Subclass->Parent (Upward Transition)
Parent->Subclass (Down-cast, Cast-Down)
12.super keyword, method to access parent within subclass
13.super() can appear on the first line of a construction method and is automatically generated by default, not creating a parent class, but being used to initialize and invoke the parent class's construction method.
14.final keyword
15.abstract abstract class
A non-abstract class calls an abstract class and must override or override the methods in the abstract class
2. Deep final keywords
1. Abstract classes cannot be modified by final keywords (abstract classes are defined to inherit)
2.fianl-decorated reference type, which can no longer be redirected to other java objects
However, a final-modified reference that points to an object whose properties can be modified.
package com.bjpowernode.java_learning; public class D53_1_FinalKeywordAddition { public static void main(String[] args) { final Customer53 c1 = new Customer53("Jack",45); // c1 = new Customer53("liuming",45); //This statement is wrong because final Keyword Modified c1 This variable // Of course we can't assign it anymore, but the following pairs c1 It is possible to assign attributes in c1.name = "jfaolj"; } } class Customer53 { String name; int age; Customer53(String name,int age){ this.name = name; this.age = age; } }
Run without error.
3. Design Mode
1. Design patterns: reusable solutions
2. Design patterns can be structurally divided into three categories: Creative, Structural and Behavioral
3. Single Case Mode
(1) The singleton mode is the simplest of the 23 design modes
(2) To solve what problems?
To ensure that there is always only one type of java object in the JVM; to save memory overhead
(3) Ways to implement the singleton pattern
i. Privatization of construction methods
ii. Provide an open, static way to get objects of the current type
ii. Provide a static variable of the current type.
package com.bjpowernode.java_learning; public class D53_2_SingletonMode { public static void main(String[] args) { Singleton53 s1 = Singleton53.getInstance(); Singleton53 s2 = Singleton53.getInstance(); System.out.println(s1==s2);//Return result true,This means that the two objects are the same object, which achieves our goal } } class Singleton53{ private static Singleton53 s;//This is critical because static variables are stored in the method area, where s Once assigned, it does not change //The second call to this class will not execute this statement statement because the class was created before the first call, and if the first call to the class changes it, it will never change //Privateize construction methods private Singleton53() { } //Provide an open access to the outside world Singleton Method of object public static Singleton53 getInstance() { if(s==null) { s = new Singleton53(); } return s; }//This must be a static method. If it is an instance method, none of our objects can be created outside. So what if we call this method? }
4. Source code:
D53_1_FinalKeywordAddition.java
D53_2_SingletonMode.java
Address:
https://github.com/ruigege66/Java/blob/master/D53_1_FinalKeywordAddition.java
https://github.com/ruigege66/Java/blob/master/D53_2_SingletonMode.java
2.CSDN: https://blog.csdn.net/weixin_44630050 (Xinyue Jun Don't Know-Rui)
3. Blog Park: https://www.cnblogs.com/ruigege0000/
4. Welcome to the WeChat Public Number: Fourier Transform, Personal Public Number, only for learning and communication, Background Reply "Gift Pack" to get big data learning materials