Java basic knowledge points (4)

Preface: Record the basic knowledge points of Java for easy familiarization and mastery.

1. Object-oriented "six principles and one rule"

"Six Principles and One Law": Single Responsibility Principle, Open-Closed Principle, Dependency Inversion Principle, Liskov Substitution Principle, Interface Segregation Principle, Synthetic Aggregation Reuse Principle and Demeter's Law.

Specific reference:

https://www.cnblogs.com/qifengshi/p/5709594.html

https://blog.csdn.net/sinat_26342009/article/details/46419873

2. Using a normal for loop to traverse the LinkedList is slow

Reason: When LinkedList gets data at any location, it will go through the previous data.

refer to:

http://www.cnblogs.com/xrq730/p/5189565.html

3. Notes on using the File class

When using the File class for IO operations, pay attention to the way of writing the file path . Both "/" and "\" can be used, but the latter needs to be escaped ( "\\" ), and File. separator can also be used As a delimiter, you can obtain delimiters under different operating systems to enhance code portability.

refer to:

http://www.cnblogs.com/xrq730/p/4886636.html

4. About polymorphism

Key Points:

When upcasting in subclasses, be aware of runtime binding issues with overridden methods. The parent class reference points to the child class object, the child class overrides the parent class method, calls the parent class method, and actually calls the method of the parent class overridden by the child class. That is, Father f = new Children(), f.toString() actually calls the toString() method in Children.

refer to:

http://www.cnblogs.com/xrq730/p/4820237.html

https://www.cnblogs.com/chenssy/p/3372798.html

5. The reason why the thread cannot start multiple times

Through the debugging of the Thread source code, when it is started for the second time, the thread state is no longer newly created, and an IllegalThreadStateException will be thrown.

if (threadStatus != 0) // Check the thread status, if it is not 0, throw an exception, 0 means the new thread 
        throw  new IllegalThreadStateException();

6. About enumeration

Note: Enumeration values ​​default to ordered numbers starting from 0

refer to:

https://www.cnblogs.com/jingmoxukong/p/6098351.html

http://www.cnblogs.com/xrq730/p/4890313.html

7. The role of final

Key Points:

1. A class modified by final cannot be inherited.

2. The method modified by final cannot be overridden.

3. Variables modified by final cannot be changed. Variables can be divided into basic data type variables and reference variables. For basic data type variables modified by final, their values ​​cannot be modified; for reference variables modified by final, their reference addresses cannot be modified, but their content can be changed. But its essence is that its reference address cannot be changed, and the content can be changed .

refer to:

http://www.cnblogs.com/xrq730/p/4820296.html

http://www.cnblogs.com/dolphin0520/p/3736238.html

8. Character encoding

Important: All characters in Java use the Unicode character set, and the encoding method is UTF-16.

refer to:

http://www.cnblogs.com/xrq730/p/4889593.html

9. Shift operation

1) Left shift: << , discard the specified digits on the left, and add 0 on the right.

2)右移:>>,丢弃右边指定位数,左边补上符号位。

3)无符号右移:>>,丢弃右边指定位数,左边补上0。

参考:

https://zhuanlan.zhihu.com/p/30108890

10.I/O模型

主要了解同步、异步、阻塞、非阻塞、同步I/O、异步I/O、阻塞I/O、非阻塞I/O,这些都是不同的概念。

参考:

http://www.cnblogs.com/dolphin0520/p/3916526.html

by Shawn Chen 2018.4.28日,上午。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325035864&siteId=291194637