Java (JVM) interview questions sharing

Original title: Java (JVM) interview questions sharing

JVM is the abbreviation of Java Virtual Machine (Java Virtual Machine). JVM is a specification for computing devices. It is a fictional computer that is realized by simulating various computer functions on an actual computer.

The Java virtual machine has its own complete hardware architecture, such as processors, stacks, registers, etc., as well as a corresponding instruction system.

The Java virtual machine is essentially a program. When it is started on the command line, it starts to execute the instructions stored in a bytecode file. The portability of the Java language is based on the Java Virtual Machine. A bytecode file (.class) can run on any platform as long as a Java virtual machine for that platform is installed. This is "compile once, run many".

Java virtual machine is not only a cross-platform language, but also a new network computing platform. The platform includes many related technologies, such as various APIs that conform to open interface standards, optimization technologies, etc. Java technology enables the same application to run on different platforms. The Java platform can be divided into two parts, namely, a Java virtual machine (Java virtual machine, JVM) and a Java API class library.

1. What is the composition and operation principle of JVM?

answer:

(1) The composition of JVM:

The JVM consists of a class loader subsystem, runtime data area, execution engine, and native method interfaces.

(2) JVM operating principle: JVM is the core and foundation of Java, a virtual processor between the Java compiler and the os platform. It is an abstract computer based on the underlying operating system and hardware platform and implemented by software methods, and can execute java bytecode programs on it. The java compiler only needs to target the JVM and generate code or bytecode files that the JVM can understand. The Java source file is compiled into a bytecode program by a compiler, and each instruction is translated into machine code for different platforms by the JVM, and runs on a specific platform.

2. Tell me about the difference between stacks?

Answer: (1) The stack memory stores local variables and the heap memory stores entities;

(2) The update speed of stack memory is faster than that of heap memory, because the life cycle of local variables is very short;

(3) Once the life cycle of the variables stored in the stack memory is over, it will be released, and the entities stored in the heap memory will be recycled from time to time by the garbage collection mechanism.

3. What are queues and stacks? What's the difference?

Answer: Queue (Queue): It is a linear table that can only be inserted at one end of the table and deleted at the other end.

Stack (Stack): is a linear list that can perform insertion and deletion operations at one end of the list.

(1) The queue is first in, first out, and the stack is first in, last out.

(2) The "restrictions" for insert and delete operations are different.

(3) The speed of traversing data is different.

4. Tell me about the execution process of class loading?

Answer: (1) First load the class of the object to be created and its direct and indirect parent classes.

(2) When the class is loaded, the static members will be loaded, mainly including the initialization of static member variables and the execution of static statement blocks, which are carried out in the order of the code when loading.

(3) After the required classes are loaded, the object is created, and the non-static members are first loaded, mainly including the initialization of non-static member variables and the execution of non-static statement blocks, which are carried out in the order of the code when loading.

(4) Finally, the constructor is executed, the constructor is executed, and the object is generated.

5. How to judge whether the object can be recycled?

Answer: Java objects will be garbage collected if they meet the following conditions:

(1) All instances have no active thread access.

(2) A circular reference instance that is not accessed by any other instance.

(3) There are different reference types in Java. Whether an instance is eligible for garbage collection depends on its reference type.

332acb41a6839d95c1116e1adb335b95.png

6. What garbage collectors does the JVM have?

Answer: (1) Serial collector

(2) ParNew collector

(3) Parallel Scavenge Collector

(4)Serial Old 和 Parellel Old

(5) Concurrent Mark Sweep Collector

Editor:

Related Posts