Java knowledge necessary for testing (I) — Java Foundation
Java Foundation
How does Java work?
The developed java source code is compiled into a platform independent bytecode file (class) through javac, and then the bytecode is interpreted into the corresponding machine code through the JVM interpreter
Understanding of "compile once, run everywhere"
It refers to the cross platform feature of Java, which is inseparable from the JVM. There is a Java running environment after JDK is installed in different environments and platforms. It does not mean that Java is a cross platform language; The key and premise of running everywhere is the JVM. Where the JVM can be run, there is a JVM operating system, so that Java provides virtual mechanisms on various platforms, so the effect of running everywhere is realized
Differences among JDK, JRE and JVM
What is encapsulation, inheritance, abstraction?
Inheritance considerations
1. A subclass can only inherit all non private members (member methods, member variables) of the parent class
2. The subclass cannot inherit the constructor of the parent class, but the constructor of the parent class can be accessed through the super keyword
The difference between equals and = =
Some conventions of hashcode and equals
a: Equals must be equal, and hashcodes must be equal
b: If you override hashcode, you should also override equals
c: The hashcode needs to be consistent, and the hash value returned by state change should still be consistent
How to understand polymorphism? Benefits? Why use polymorphism?
Polymorphism: the reference of the parent class points to the child class
Benefit: the function of the subclass can be called by the method or reference variable of the parent class
Why: reusability, high cohesion, low coupling, scalability
The difference between super and this
Code block execution order
Static code block (executed only once) - > construction code block (executed before each execution of construction method) - > construction method
Normal class initialization order
Static attribute (variable, method) - > static code block - > member attribute - > construction code block - > constructor
Inherited subclass initialization order
Parent static attribute - > parent static code block - > child static attribute - > child static code block - > parent member variable - > parent construction code block - > parent construction method - > child member variable - > child construction code block - > child construction method