preface
This is the third article in the recommended java series. There are a lot of contents in this section. It is a new concept for Xiaobai. If you want to master it skillfully, you need a lot of practice. The guide map of this section will be very large. The small editor will provide the guide map separately before explaining each knowledge point. Of course, the whole map is also available. In addition, this section will involve many system API s, and we need to learn to read jdk documents, so we will also provide you with jdk1.8 help documents. See the end of the article for download.

If there is a picture and a truth, I won't say much. The knowledge points are basically twice that of the previous article.
Design pattern

The 23 design patterns in Java are widely used in development, not only in our usual application development, but also in some frameworks and system source codes. The specific content can not be mechanically copied, but to experience this process from experience and think about the timing and scenarios of applying design patterns.
The singleton design pattern is the most commonly used and simplest. It can be said that singleton design pattern will be used in almost all programs developed in Java language. There is no need to stick to the concept. It is important to understand its ideas. With the accumulation of development experience, we will slowly realize the mystery!
/** * Lazy style */ public class SingletonLazy { private static SingletonLazy singletonHungry; private SingletonLazy() { } public static SingletonLazy getInstance() { if (singletonHungry == null) { singletonHungry = new SingletonLazy(); } return singletonHungry; } }
/** * Hungry Han style */ public class SingletonHungry { private static SingletonHungry singletonHungry = new SingletonHungry(); private SingletonHungry() { } public static SingletonHungry getInstance() { return singletonHungry; } }
polymorphic

Polymorphism is one of the three characteristics of Java object-oriented. Encapsulation and inheritance were discussed in the previous article. Polymorphism is the first key content of this section. In short, the multiple forms of a transaction are called polymorphism.
It is difficult to understand in abstraction. For example, the actual scene is easier to understand:
For example, our software developers themselves are abstract, because it is not easy for people in other industries to understand, and it is not clear what you are developing? (front-end development or back-end development? java development or PHP development? System layer development or game development? Etc.), this concept is generally abstract, but we still know what the word has in common, and the commonness here is the concrete ability abstracted. It is called abstract method in java, Because each specific developer has different internal capabilities of the same method, this is what specific subclasses need to implement. The subclasses here can be understood as java development engineers, PHP development engineers, and so on.
In our actual development, according to the business scenario, we have to extract abstract classes ourselves to realize the ability of separation, and the separated multiple subclasses have different forms, that is, multiple forms, so they are called polymorphic.
Keyword instanceof
I believe you can understand that we have extracted the abstract class (parent class), so the performance of subclasses is different, and how does the parent judge whether a subclass is its subclass? This is the use of the keyword instanceof.
Learning polymorphism may hear the most sentence is: the parent class reference points to the child class object.
What is a reference? It is called a handle in the old version of the textbook. The tutorials at the new point are called references. In fact, they are variables of the created object, such as:
// A programmer is a handle, also known as a reference Programmer programmer = new Programmer();
Another example is when a parent class reference points to a child class object:
// new is used to create objects. We all used it in the previous section Programmer javaProgrammer = new JavaProgrammer();
interface
Let's look at the guide map and remember the usage and why. In actual development, there are too many scenarios for defining interfaces, so you must master the use rules.
Summary
Polymorphic content is the top priority. We must understand the following concepts and why? This is also a common interview question.
- How do you understand polymorphism in Java?
- How do you understand abstract classes? What are the characteristics of abstract classes?
- Why does Java have an interface?
- Usage rules of interfaces and definitions of methods in interfaces
- Application scenarios of internal classes?
abnormal

This content can only be solved by relying on the prompt of the IDE in the development. More applications are the processing when developing the SDK or encapsulating components, clarifying the execution sequence of the program when exceptions occur, and the rules for throwing exceptions when the parent method throws exceptions and when the child class rewrites.
Packaging

- Clearly why there should be packaging?
- Master the rules of packing and unpacking and the use of type conversion methods
The conversion methods mentioned in the map are often used in development. We should practice more. At least, we should try all the basic data types once.
The following codes are the focus of this section:
private static void compareDemo() { Integer num1 = 20; /** * It is equivalent to executing Integer num2 = Integer.valueOf(2021); * * Double And Float do not have this feature (constant volume pool) */ Integer num2 = 2021; Integer num3 = 20; Integer num4 = 2021; System.out.println("num1 Is it equal to 20 " + (num1 == 20)); // Automatic unpacking comparison System.out.println("num2 Is it equal to 2021 " + (num2 == 2021)); /** * Reasons for different results: when the Integer is between - 128 and 127, it will be unpacked automatically before participating in the comparison of two Integer objects. If it exceeds this range, it will not be unpacked */ System.out.println("num1 And num3 Equal " + (num1 == num3)); // 30 figures are being compared System.out.println("num2 And num4 Equal " + (num2 == num4)); // Object in comparison }
character string

Each Java developer must master this part. String interception, replacement, matching, case conversion, search and splicing are the most commonly used operations. The methods listed in the guide diagram must be skillfully used.
aggregate

The key contents in the guide map are marked, which is the top priority. The collection content in Java is also one of the most knowledge points in the interview, which must be kept in mind and used skillfully. ArrayList and HashMap are the most commonly used collections in development. We must understand their respective characteristics, common methods and unique methods. Most scenarios use both, such as conditional filtering.
thread

First, we should find out the relationship between the default sequence of program execution and the main thread; Secondly, we should understand how the program executes when there are multiple threads; After these two problems are clarified, you will understand when to create threads.
Knowledge points (also interview questions):
- How threads are created
- Execution order of threads
- Understanding of synchronized keyword
- Thread deadlock problem
IO

This part of the content is used in combination with network requests in actual development, such as downloading files, uploading files, modifying avatars, etc. the specific API usage here is the most native, that is, the underlying implementation logic is like this. In actual development, we often use the framework encapsulated by others, and we can't see the innermost API implementation. The framework will leak some methods to us, Maybe you can download or upload in one sentence; However, we still need to manually roll out some scenes, so we still need to master the core code of these principles. Occasionally, you will dictate the process during the interview.
The following code is about three methods of creating files by File class, which may be used according to business:
/** * Several ways to create a File * * @param parentPath Front end path * @param fileNamePath Back end path */ private static void createFile(String parentPath, String fileNamePath) { File file1 = new File(parentPath + "\\" + fileNamePath); System.out.println("file1 is exit ? " + file1.exists()); File file2 = new File(parentPath, fileNamePath); System.out.println("file2 is exit ? " + file2.exists()); File file3 = new File(new File(parentPath), fileNamePath); System.out.println("file3 is exit ? " + file3.exists()); }
summary
jdk1.8 help document download: https://pan.baidu.com/s/12JHAlmwZbtBiJlPNZPlf3Q Password: d5ya (this document is downloaded from the Internet by Xiaobian. Please don't believe it if there are other contents in it)
For these three articles, Xiaobai suggests that after learning them in 15 days, they must be steady. This is the most basic thing of Java. No matter how awesome the framework to be contacted later, the bottom layer is inseparable from the support of the foundation.
Supplementary content: enumeration in Java (Enum)
It is relatively simple. If you search by yourself and are familiar with the writing method, the subsequent project chapters will be applied.