preface

Last week published the first recommended learning Java series, the content of zero basic white can understand, today this content is more, is also more important content, xiaobian will first on a mind map, to help you understand each knowledge point and hierarchy.

Knowledge map

Explanation: This part of the content can be said to really enter the programming horizon, because it has involved logic and thinking. The first is the most basic Java coding rules and structures, such as operators, flow control statements, loops, arrays, and methods in maps. The latter aspect of object-oriented, and the three features of object-oriented: encapsulation, inheritance, and polymorphism, are more intellectual, which requires you not only to master the basic Java syntax and rules, but also to try to understand object-oriented ideas.

The following will be explained one by one, specific or to write more, more practice, put can understand the mystery of ah!

The operator

In fact, every programming language has the most basic operational logic, but each has its own form of expression, to whom? (computer), so this content is not difficult to understand, the key is to master the writing and operation sequence.

The most important details here:

  • Self-addition (++) and self-subtraction (–) are written before and after variables, and their operation timing is different
  • The assignment operator in Java is:=Rather than= =
  • Logical operators in the actual development of the application of the scene is particularly many, to master

Flow control statement

In short, the conditional judgment processing in program execution (sequential execution). There are three main forms: if, if-else, and switch-case. These three are very common in practical development and belong to the focus of the content.

Execution instructions and application scenarios:

  • If condition: single if statement or multiple single IF statements can determine whether the program is processing a condition that satisfies one or more conditions
  • if-else: Single use or nested use scenarios of complex conditions to deal with whether a specific condition is satisfied in multiple judgments of a certain business
  • switch-case: The execution structure of the program is very similar to that of multiple ifsswitch-caseIs the type of judgment conditionIf statementMore,ifThe condition accepts the logic as true or false, andswitch-caseYou can also combine basic data types andStringType as condition

Switch-case, for example, is simpler than if, and easier to merge and split cases

private void switchCaseMethod(String language) {
    switch (language) {
        case "java":
            System.out.println("hello " + language);
            break;
        case "kotlin":
            System.out.println("kotlin first for Android Development");
            break;
        case "c++":
        case "c":
            System.out.println("c and c++");
            break;
        default:
            System.out.println("default case");
            break; }}Copy the code

cycle

These contents are also important, especially for loop, the actual development almost always use, most of the cases are combined with the array and collection to learn later use, recommend you to practice several cases, especially pay attention to the index problem, avoid the occurrence of out-of-bounds exceptions.

An array of

One-dimensional arrays are the most commonly used in development, except for special jobs (e.g., algorithm engineers). Focus on the dynamic assignment of the array, value according to the index and traversal operations.

methods

This section is mainly about how to write and the rules of writing, calls between methods and return values. In short, you can write all kinds of methods. After learning about inheritance and polymorphism, you will have a deeper understanding of methods.

In real development, the code is done through methods. The approach is to perform a specific task unit, following the single responsibility principle.

object-oriented

It’s important to understand this idea. For example, in programming contests, there are many questions that can be answered by brute force, but this is not object-oriented programming. Always remember that Java is object-oriented and everything is an object. Once we understand this, we can create the appropriate class.

Content to master:

  • Object-oriented thinking
  • Create a class
  • The composition of the class
  • Class constructor and initialization order
  • Features: encapsulation, inheritance, polymorphism

encapsulation

The simple understanding is:

  • Where is the class stored?
  • How open is it to the outside world?
  • Should the class be inherited?
  • Do variables of this class need to be shared by N objects?
  • Should the class have a shared code block?

Keep this in mind. In real development, N packages will be created, and each package will have multiple classes, so you need to be aware of this when creating classes.

inheritance

Inheritance, if you try to understand it, is an extended relationship. Inheritance must occur between a subclass and a parent class, and Java only supports single inheritance (a subclass can inherit only one parent class). If there is a case where you need more inheritance, the next article will cover a topic called interface, which will solve this problem.

The important thing to understand is when should you inherit? As well as the details of the map, repeated practice, master, this is the core of the foundation.

conclusion

More on polymorphism in the next article. If you are choosing what programming language to learn, then I recommend you to learn Java.

Xiaobian specially created a public number: recommend learning Java, will share Java related content, and the original, welcome to search attention (attention is to send xiaobian selection of high-quality video tutorials and electronic information), learn Java together!