preface

As a Java practitioner, you will inevitably be asked about JVM knowledge when looking for a job. Knowledge of the JVM is seen by many interviewers as an important measure of a candidate’s technical depth. Here we’ll take a closer look at common JVM interview questions and provide standard answers.

Java Oop, Java Collection containers, Java exceptions, concurrent programming, Java reflection, Java serialization, JVM, Redis, Spring MVC, MyBatis, MySQL database, messaging middleware MQ, Dubbo, Linux, ZooKeeper, distributed & data structure and algorithm and other 26 thematic technical points are summarized by the small editor in each big factory interview real questions, there have been many fans with this PDF to win many big factory offer. Today, here is a summary to share to everyone! [Continuously updated!]

The full version of the Java interview questions address: 2021 latest interview questions collection collection.

The serial number project content link
1 The middleware Java Middleware (2021) Juejin. Cn/post / 694870…
2 Micro service Java Microservices (2021) Juejin. Cn/post / 694906…
3 Concurrent programming Concurrent Programming in Java (2021 latest Edition) Juejin. Cn/post / 695053…
4 Java based Java Basics (2021) Juejin. Cn/post / 695062…
5 Spring Boot Spring Boot Interview Questions (2021 Latest edition) Juejin. Cn/post / 695137…
6 Redis Redis Interview Questions (2021 Latest edition) Juejin. Cn/post / 695166…
7 Spring MVC Spring MVC (2021) Juejin. Cn/post / 695166…
8 Spring Cloud Spring Cloud Interview Questions (2021) Juejin. Cn/post / 695245…
9 MySQL optimization MySQL optimize interview questions (2021 latest edition) Juejin. Cn/post / 695246…
10 JVM JVM Performance Tuning Interview questions (2021 Latest Edition) Juejin. Cn/post / 695246…
11 Linux Linux Interview Questions (2021 latest edition) Juejin. Cn/post / 695287…
12 Mybatis Mybatis (2021 latest Edition) Juejin. Cn/post / 695287…
13 Network programming TCP, UDP, Socket, Http Network programming interview (2021 latest edition) Juejin. Cn/post / 695287…
14 Design patterns Design Mode Interview Questions (2021 Latest edition) Juejin. Cn/post / 695544…
15 Big data 100 Big Data Interview Questions (2021 latest edition) Juejin. Cn/post / 695544…
16 Tomcat Tomcat Interview Questions (2021 Latest edition) Juejin. Cn/post / 695570…
17 multithreading Multithreaded Interview Questions (2021 Latest edition) Juejin. Cn/editor/draf…
18 Nginx Nginx_BIO_NIO_AIO interview Questions (2021 Latest edition) Juejin. Cn/editor/draf…
19 memcache Memcache Interview Questions (2021 latest edition) Juejin. Cn/post / 695608…
20 Java exception Java Exception Interview Questions (2021 Latest edition) Juejin. Cn/post / 695644…
21 The Java virtual machine Java Virtual Machine Interview (2021 latest edition) Juejin. Cn/post / 695658…
22 Java collection Java Set Interview Questions (2021 Latest edition) Juejin. Cn/post / 695684…
23 Git Git Git Command (2021) Juejin. Cn/post / 695692…
24 Elasticsearch Elasticsearch (2021 Latest Edition) Juejin. Cn/post / 695840…
25 Dubbo Dubbo Interview Questions (2021 Latest edition) Juejin. Cn/post / 695842…

1. When can stack memory overflow occur?

2. Detail the JVM memory model

Draw a diagram of the JVM memory model for the interviewer and describe the definition of each module, its functions, and possible problems such as stack overflow.

My answer:

JVM memory structure

3. Why should JVM memory be divided into new generation, old generation, persistent generation? Why should the new generation be divided into Eden and Survivor?

4. What is a complete GC flow in the JVM, and how are objects promoted to older generations

5. You know which types of garbage collectors, their advantages and disadvantages, focusing on CMS and G1, including principles, procedures, advantages and disadvantages.

6. How much do you know about the JVM memory model, such as reordering, memory barriers, happening-before, main memory, working memory?

Volatile (volatile) : Volatile (volatile) : volatile (volatile) : volatile

My answer:

1) Java Memory model diagram:

The Java memory model stipulates that all variables are stored in the main memory, and each thread has its own working memory. The working memory of the thread stores a copy of the main memory of the variables used in the thread. All operations on variables must be carried out in the working memory of the thread, instead of reading and writing the main memory directly. Different threads cannot directly access variables in each other’s working memory, and the transfer of variables between threads requires data synchronization between their own working memory and main memory.

2) Instruction reordering.

Here, let’s take a look at some code

public class PossibleReordering { static int x = 0, y = 0; static int a = 0, b = 0; public static void main(String[] args) throws InterruptedException { Thread one = new Thread(new Runnable() { public void run() { a = 1; x = b; }}); Thread other = new Thread(new Runnable() { public void run() { b = 1; y = a; }}); one.start(); other.start(); one.join(); other.join(); System.out.println(" (" + x + ", "+ y +") "); }Copy the code

The run result may be (1,0), (0,1), or (1,1), or (0,0). This is because, at actual runtime, code instructions may not be executed strictly in the order of code statements. Most modern microprocessors use out-of-order execution (OoOE or OOE), where conditions permit the execution of subsequent instructions that are currently capable of executing immediately, avoiding the wait for the data needed for the next instruction. By using out-of-order execution techniques, the processor can greatly improve execution efficiency. And this is

Order rearrangement.

7. Tell me briefly what you know about classloaders. Can they break parental delegation and how?

Parental delegation model diagram:

8. Describe the main JVM parameters you know

9. How to display thread stack information.

10. Strong reference, soft reference, weak reference, virtual reference difference?

11. Memory models and partitions need to be detailed to what is placed in each partition.

12. Partitions in the heap: Eden, Survival (from+ to), old age, their respective characteristics.

13. How about Java garbage collection?

14. What are the methods of garbage collection in Java?

15. Java memory model

16. Java class loading process?

17. What is the Java class loading mechanism?

The virtual machine loads the data describing the Class from the Class file into memory, verifies, parses, and initializes the data, and eventually forms Java types that the virtual machine can use directly.

Class loader parent delegate model mechanism?

When a class receives a class loading request, it does not load the class first. Instead, it delegates to the parent class, and the parent class loads the class. If the parent class fails to load the class, the parent class sends feedback to the child class, and the child class completes the class loading.

19. What is a class loader and what are class loaders?

20. Briefly describe the Java memory allocation and reclamation policy and the Minor and Major GC

  • Objects are allocated in the Eden area of the heap first.
  • Big object goes straight to the old age.
  • If there is not enough space in Eden area for allocation, the virtual machine will perform a Minor GC.Minor GC usually occurs in Eden area of the new generation. Objects in this area have a short lifetime and tend to have a high frequency of GC and a fast recovery speed. Full /Major Gc occurs in the old generation. Normally, the old generation Gc does not trigger a Minor Gc, but can be configured to do a Minor Gc before Full Gc to speed up the old generation collection.