This article is only a personal review and summary of Java. It involves knowledge points with a lot of code or content. A separate article will be dedicated to it. If there are any errors, please correct me.
1. Java Overview
1.1.Father of Java
James Gosling was born in Canada and is a computer programming genius. While studying for a doctorate in computer science at Carnegie Mellon University, he wrote a multi-processor version of the Unix operating system and served as the leader of Sun's Oak project team. Oak was later renamed Java, so he is not only a master of the Java programming language One of the co-founders, he is generally recognized as the "Father of Java".
1.2.Basic introduction to Java
Pictures from 360 Encyclopedia
1.3.Java installation and environment configuration
It mainly configures JDK and JRE. For example tutorials, see Java/JDK installation and environment configuration.
1.4.Java memory division
When the Java virtual machine executes a Java program, the memory it manages will be divided into 5 different data areas (can also be subdivided into 7 different areas): program counter, Java virtual machine stack, local method stack, Java heap , method area.
1.5. Introduction to the differences between Java and C/C++
Java is developed from C++, retains most of the content of C++, and has optimized and simplified some aspects. Here we only introduce the language differences, not the scope of use, and do not reflect the superiority.
1.5.1.Pointer
Java has no concept of pointers , which effectively prevents pointer operation errors that are easy to occur in the C/C++ language (such as system crashes caused by dangling pointers) and ensures the safety of the program. In C/C++, errors often occur when pointers operate on memory.
But Java has references.
1.5.2. Multiple inheritance
C++ supports multiple inheritance , which allows multiple parent classes to derive a subclass, that is, a class can inherit multiple parent classes. Although multiple inheritance is powerful, it is complex to use. In layman's terms, C++ allows a class to have multiple adoptive parents. The class can inherit the "property" of the adoptive parents, but the relationship needs to be adjusted to make them coexist harmoniously.
Java does not support multiple inheritance , but allows a class to implement multiple interfaces. That is to say, Java does not recognize the existence of adoptive fathers, and only inherits one-to-one by blood. There is less inheritance, but it is easier to use.
1.5.3. Garbage Collection (GarbageCollection)
The picture comes from 360 Encyclopedia
In C++, development needs to manage memory by itself. In Java, the JVM has its own GC mechanism . Although it has its own GC mechanism, OOM and memory leak problems may also occur. There is a destructor in C++ and the finalize method of Object in Java.
1.5.4. Operator overloading
C++ operators can be overloaded, but not in Java. At the same time, forced automatic transformation is supported in C++, but not in Java. ClassCastException (type mismatch) will occur.
1.5.5. Compile and run
The Java source code will first be compiled once and become intermediate code (bytecode.class). The intermediate code is then interpreted into machine code by the interpreter, which is built into the JVM. A brief introduction is as shown below, and a detailed introduction is as follows: See the Java compilation process from the JVM
The C++ source code is compiled once and directly linked during the compilation process to form machine code.
Therefore, C++ executes faster than Java, but Java can use the JVM to be cross-platform.
2. Basics of Java programming
2.1.Permission modifiers
2.1.1. Introduction
There are four access modification qualifiers in Java: private, default (default access rights), protected and public. Only default access and public can be used to modify classes. All four permissions are available for modifying class variables and methods.
private: If a method or variable of a class is modified with private, then the method or variable of this class can only be accessed within the class itself, and cannot be accessed explicitly outside the class or in other classes.
default (default access permission): If a method or variable of a class is modified by package access permission, it means that the method or variable of this class can only be explicitly called in other classes in the same package. A class cannot explicitly call methods or variables of the class.
protected: If a method or variable of a class is modified with protected, the method or variable of this class can be accessed by classes in the same package. For classes in different packages, only classes that inherit from the class can access the methods or variables of the class.
public: Methods or variables modified by public are visible everywhere.
2.1.2.Scope
scope | private | default | protected | public |
Same class in the same package | √ | √ | √ | √ |
Different classes in the same package | √ | √ | √ | |
Subclasses in different packages | √ | √ | ||
non-subclasses in different packages | √ |
2.2. Eight basic types
2.2.1. Introduction
Since the birth of the JAVA world, there have been eight basic "containers", also known as basic data types. They are byte, short, int, long, float, double and char.
They can be simply classified into the following 4 categories by type:
- Logical type: boolean
- Integer types: byte, short, int, long
- Character type: char
- Floating point types: float, double
Include Java identifiers
Four major reference types
statement
operator
3. Java keywords
static
this
super
final
.......
4. Program flow control
order
select(branch)
cycle
5. Method
Necessity of method
method format
6. Object-oriented
The three major characteristics of object-oriented: encapsulation, inheritance, and polymorphism.
7. Abstract and Interface
The format, characteristics and differences between abstractions and interfaces
8. Access permission modifiers
public、protected、default、private
9. Internal classes
Category: member inner class, static inner class, local inner class, anonymous inner class
java basics advanced knowledge
10. Collection system
List and Map
11. Abnormal System
Thorwable
12. Multi-threading
The concept of thread
Characteristics of threads
Use of threads