头图

A review of Java introductory knowledge (below)

code小生
中文

Preface

This is recommended to learn java. There is a lot of content in this section. For Xiaobai, it is a new concept. If you want to master it, you need a lot of practice. The map in this section will be very large. The editor will provide a separate map before explaining each knowledge point. Of course, the whole map is also available. In addition, this section will involve many system APIs, and we have to learn to look at it. jdk document, so we will also provide you with jdk1.8 help document, download it at the end of the article.

知识点枝节数目

I won’t say much if there are pictures and the truth, the knowledge points are basically twice as much as in the previous article.

Design Patterns

Java设计模式导图

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 cannot be mechanically applied, but to experience this process through experience. Think about the timing and scenarios of applying design patterns.

Among them, the singleton design pattern is the most commonly used and the simplest. It can almost be said that the singleton design pattern is used in all programs developed in the Java language. There is no need to smash the concept, it is important to understand its thoughts. With the accumulation of development experience, you will slowly realize the mystery!

/**
 * 懒汉式
 */
public class SingletonLazy {

    private static SingletonLazy singletonHungry;

    private SingletonLazy() {
    }

    public static SingletonLazy getInstance() {
        if (singletonHungry == null) {
            singletonHungry = new SingletonLazy();
        }

        return singletonHungry;
    }

}
/**
 * 饿汉式
 */
public class SingletonHungry {

    private static SingletonHungry singletonHungry = new SingletonHungry();

    private SingletonHungry() {
    }

    public static SingletonHungry getInstance() {
        return singletonHungry;
    }

}

Polymorphism

Java多态导图

polymorphism is one of the three major characteristics of Java object-oriented. The previous article talked about encapsulation and inheritance. Polymorphism is the first focus of this section. The meaning to be expressed is to put it simply: the multiple forms of a transaction are called polymorphism.

It is not easy to understand in abstraction, but it is easier to understand the actual scene as an example:

For example, our software developers themselves are an abstract category, because it is not easy for people in other industries to understand, and it is still not clear. What exactly are you developing? (Is it front-end development or back-end development? Is it Java development or PHP development? Is it system-level development or game development? etc.) This concept is generally abstract, but you probably know what the word has in common , And the commonality here is the abstracted concrete ability, which is called abstract method in Java, because each concrete developer has a different internal ability of the same method, and this is what concrete subclasses want to achieve. The subclasses here can be understood as java development engineer, PHP development engineer and so on.

In our actual development, according to the business scenario, we have to extract the abstract class ourselves, and then realize the separation ability, and the separated multiple subclasses have different manifestations, which are multiple forms, hence the name polymorphism .

Keyword instanceof

I believe you can understand that we have extracted the abstract class (the parent class), so the performance of the subclasses is different, and how does the parent class judge whether a subclass is its subclass? This is the purpose of the instanceof

The one sentence you may hear most when learning polymorphism is: parent class reference points to the subclass object .

What is reference , the old version of the textbook is called handle, new tutorials are called reference, in fact, it is the variable of the created object, such as:

// programmer 就是句柄,也叫引用
Programmer programmer = new Programmer();

Let's give another example of a parent class reference pointing to a child class object:

// new 是用来创建对象的,上一节大家都用过
Programmer javaProgrammer = new JavaProgrammer();

interface

For this piece of content, look at the map and remember the usage and why. In actual development, there are too many scenarios for defining interfaces, and you must be proficient in the rules of use.

summary

polymorphism is the top priority. It is necessary to understand the following concepts and why? This is also a common interview question.

  1. How do you understand polymorphism in Java?
  2. How do you understand abstract classes? What are the characteristics of abstract classes?
  3. Why does Java have an interface?
  4. The usage rules of the interface and the definition of the methods in the interface
  5. Application scenarios of internal classes?

abnormal

Java中的异常知识导图

This piece of content can only be handled by relying on the IDE in the development. More application situations are the processing when developing SDK or packaging components by yourself. When an exception occurs, the execution order of the program is clear, and the parent class method throws exceptions. , The rules for throwing exceptions when subclasses are rewritten.

Packaging

Java中的包装类知识导图

  • it clear why there is a packaging category?
  • Familiar with the rules of boxing and unboxing and the use of type conversion methods

The conversion methods mentioned in the map are often used in development. You should practice more, and at least try all the basic data types once.

The following code is the focus of this section:

private static void compareDemo() {

    Integer num1 = 20;

    /**
     * 相当于执行了 Integer num2 = Integer.valueOf(2021);
     *
     * Double 和 Float 不具备这个特性(常量池)
     */
    Integer num2 = 2021;

    Integer num3 = 20;
    Integer num4 = 2021;

    System.out.println("num1 与 20 相等吗 " + (num1 == 20));
    // 自动拆箱比较
    System.out.println("num2 与 2021 相等吗 " + (num2 == 2021));

    /**
     * 结果不同的原因:Integer在 -128~127 之间时,参与两个 Integer 对象比较前会自动拆箱,超过这个范围则不会
     */
    System.out.println("num1 与 num3 相等吗 " + (num1 == num3)); // 30 数字在比较
    System.out.println("num2 与 num4 相等吗 " + (num2 == num4)); // 对象在比较
}

String

Java中的字符串知识导图

Every Java developer must master this part of the content. The interception, replacement, matching, case conversion, search, and splicing are the most commonly used operations. The methods listed in the map must be used proficiently.

set

Java中的集合知识导图

The key content in the map is marked, which is the top priority. The collection content in Java is also one of the most frequently asked knowledge points in the interview. You must keep it in mind and use it skillfully. ArrayList and HashMap are the most commonly used collections in development. must understand their respective characteristics and common methods and unique methods . Most scenes are used in combination with the two, such as: conditional filtering operations.

Thread

Java中的线程知识点导图

First of all, we must understand the relationship between the default order of program execution and the main thread; second, we must understand how the program is executed when there are multiple threads; after these two issues are cleared, you will understand when you need Create a thread.

Knowledge points (also interview questions):

  • create threads
  • thread execution order
  • of the synchronized keyword
  • thread deadlock problem

IO

Java中的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, often we will use it in actual development Frameworks encapsulated by others cannot see the implementation of the innermost API. The framework will expose some methods to us, maybe download or upload in one sentence; but some scenes still need us to manually roll it again, so the core code of these principles Still need to master, occasionally interviews will let you dictate the process.

The following codes are about File three ways to create files, which may be used according to the business:

/**
 * 创建文件 File 的几种方式
 *
 * @param parentPath   前端路径
 * @param fileNamePath 后端路径
 */
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());
}

to sum up

jdk1.8 help document download: https://pan.baidu.com/s/12JHAlmwZbtBiJlPNZPlf3Q password: d5ya (this document is downloaded from the Internet by the editor, if there are other contents in it, please don’t believe it)

These three articles are recommended for Xiaobai to study in 15 days and must be steady and steady. This is the most basic thing of Java. No matter how awesome the framework is to be touched later, the bottom layer cannot be separated from the basic support.

supplementary content : Enumeration in Java (Enum)

It's relatively simple, you can search for it yourself and be familiar with the writing, and the subsequent project chapters will be applied.

The editor specially created a public : 160c1793a5a3f4 recommended to learn java, will share java , and is based on originality, welcome everyone to search and pay attention (if you follow, send the boutique video tutorial selected by the editor), and learn Java together!
阅读 395

codexiaosheng
在专注于 Android 的同时,倾向 T 型发展,欢迎围观我的公众号「code小生」
132 声望
14 粉丝
0 条评论
你知道吗?

132 声望
14 粉丝
宣传栏