When asked about jvm (Java Virtual Machine) in an interview, how do you introduce the interviewer to his own rhythm?

Preface

As a Java development engineer, whether it is school recruitment or social recruitment, jvm must be a must-know knowledge point. Although it is not used much in real development, it can even be said that it is not used ( for those who are new to the industry or beginners in Java ), but when the interviewer asks, he just wants to test the breadth of your knowledge. If you can answer it well, , then congratulations, you have won the interviewer's favor. You will feel confident in the interview ahead.
Of course, if you have a deep understanding of jvm , you can alsoDirect the interviewer toAt your own pace. When introducing yourself, you can emphasize that you are familiar with jvm , then the interviewer will have a high probability of asking about jvm.
This article will introduce in detail how to answer JVM-related interview questions during the interview. Although you can't scorn the interviewer, you can at least have a meaningful conversation with the interviewer, which will give you a guarantee for getting the offer.

Quick questions and answers

如果你对jvm只是了解一点,可以先说jvm**是什么****有哪些功能**

You can answer like this

Regarding jvm, I only have a brief understanding of it .
JVM (Java Virtual Machine) is one of the core components of the Java platform. It is a virtual machine that can execute Java bytecode. JVM provides an environment for Java programs to run, enabling cross-platform Java applications to run on different operating systems.
The main functions of JVM include the following aspects:

  • Class loading: The JVM is responsible for loading the bytecode files obtained after compiling the Java source code into the memory, and performs verification, preparation, and parsing steps, and finally stores the class information in the method area.
  • Memory management: JVM manages the memory space required for program running, including heap memory, stack memory, method area, etc. It is responsible for memory allocation and recycling, and automatically releases the memory space occupied by objects that are no longer used through the garbage collection mechanism.
  • Execution engine: The execution engine of the JVM interprets or compiles the bytecode files loaded into the memory into machine code and executes the program instructions. Depending on the implementation method, the execution engine can use interpreted execution or just-in-time compilation to improve execution efficiency.
  • JIT compiler: The JIT (Just-In-Time) compiler is part of the JVM. During the running of the program, the JIT compiler will dynamically compile frequently executed hot code to improve execution efficiency.
  • Exception handling: JVM provides an exception handling mechanism to capture and handle exceptions in the program, and provides corresponding exception handling mechanisms for processing.
  • Security mechanism: JVM provides a security manager to implement security restrictions and control on Java applications running in it.

In short, as the core component of the Java platform, the JVM plays a key role in interpreting and executing Java bytecode . It allows developerswrite once, and then inRun Java applications on different operating systems and hardware platforms, realizing the cross-platform features of Java.

To attract good ideas

如果你对jvm很熟,那么你就可以大展身手了。

The interview process is often very short, and there is a lot of Java-related interview content. We need to remember all kinds of content, which is obviously very difficult, so if you want to rely on jvm to win over the interviewer, then we canPlay a little trick. For the interviewer, he wants to quickly understand your mastery of knowledge, and it is often difficult for him to make moves, so we need toGuidance to the interviewer's interest.
After that, you can say one more thing:

Class loading process
Java memory structure
JVM garbage collection mechanism
Garbage collection algorithm
Garbage collector

You can answer this:

JVM contains two subsystems and two components. The two subsystems are Class loader and Execution engine; the two components are Runtime data area and Native Interface.
At the same time, I also learned:

Give a rough idea based on the following content. The premise is that you understand these contents

  • Class loading process

The class loading process is mainly divided into three parts: loading, linking, and initialization, and the linking can be subdivided into three small parts: verification, preparation, and parsing.
Loading : Simply put, loading refers to loading class bytecode files from various sources into memory through the class loader.
Verification : mainly to ensure that the loaded byte stream complies with the virtual machine specifications and will not cause security errors.
Preparation : mainly to allocate memory for class variables (note, not instance variables) and assign initial values.
Analysis : The process of replacing symbol references in the constant pool with direct references.
Initialization : This stage is mainly the initialization of class variables and the process of executing the class constructor.
In other words, only statically modified variables or statements are initialized.

Regarding class loading, the interviewer here may ask:
1. The process of creating objects in Java
2. Parental delegation mechanism
3. What class loaders are there
4. Can the double-clear delegation mechanism be broken? How to break? Why break? for example.
5. When will the loading of the class be triggered
(the answers can be sorted out by yourself first: all subsequent jvm-related interview questions will be sorted into pdf files and updated to the WeChat public account: Xiaochen must be confident)

  • Java memory structure

According to the figure below, let’s focus on what parts the runtime data area consists of.
The runtime data area mainly consists of heap, method area, stack, program counter, and local method stack.
Insert image description here

The interviewer may ask here:
1. Which parts of the runtime data area are thread-private? Which ones are public?
2. What changes are there in jdk1.8 in the method area.
3. Do you understand memory leaks and memory overflows?
4. The difference between method area, permanent generation, and meta space

  • jvm garbage collection mechanism

The jvm garbage collection mechanism adopts the idea of ​​generational recycling, which divides the memory area into the new generation and the old generation. The Cenozoic Era is divided into the Eden Zone and the Survival Zone, and the Survival Zone is composed of two zones of equal size. The newly created object will be in the Eden area, and then it will enter the survivor area 1 through GC. If the GC has not been cleaned up again, it will enter the survivor area 2. If it has experienced GC again in the survivor area 2 and has not been cleaned up, Will enter the survival zone 1 again. There is no transition between the survival zones. The subject's age will be increased by one. When the age reaches 15, it will enter the old age.

Here the interviewer may ask:
1. The default size ratio between the Eden area and the survivor area
2. Will only objects aged 15 years enter the elderly area? Can 15 be changed to 16?
3. Do you understand dynamic age judgment?
4. Why is the memory of Eden area much larger than that of survivor area?

  • Garbage collection algorithm

At the same time, I also understand the garbage collection algorithm: mark sorting, copy algorithm, clear mark, generational collection algorithm.

Here the interviewer may ask:
1. Explain the copy algorithm in detail
2. The difference between copy algorithm, mark sorting and mark clearing
3. How to judge whether it is a garbage object

  • Garbage collector

I also know some garbage collectors.
New generation collectors (all copy algorithms): Serial, ParNew, Parallel Scavenge.
Old generation collectors: CMS (marking-cleaning), Serial Old (marking-cleaning), Parallel Old (marking) Collation)
Whole heap collector: G1 (mark-clear algorithm in one Region, copy algorithm between 2 Regions)

The icing on the cake

Let’s talk about some jvm monitoring and troubleshooting tools

Recommended books

A comprehensive guide to the core technology of Java virtual machine :
Author: Li Bo, senior architect, expert blogger of InfoQ platform and Alibaba Cloud community, CSDN blog expert, 51CTO lecturer, MOOC lecturer, keen participant in Quarkus technology community, participated in Development and in-depth research of multiple open source projects (Skywalking, Nacos, Pulsar, etc.). Currently serving as the vice chairman of the company's internal architecture committee, his main research directions are "the promotion of cloud-native Java microservice architecture based on Quarkus" and "the internal implementation of GraalVM virtual machine".

This book mainly focuses on the basic characteristics and operating principles of the Java virtual machine.Analyze the structure and underlying implementation of JVM in a simple and in-depth way,Introducing many performance tuning solutions and how to use tools. Finally, it also expands on the implementation principles of the JMM memory model and the optimization mechanism of the Java compiler , allowing readers to not only learn the core technical knowledge of the JVM, but also consolidate the technical foundation of JVM tuning and code optimization.

Insert image description here

This book is suitable for reference reading by developers, project managers, architects and performance tuning engineers who already have a certain foundation in Java programming. At the same time, this book can also be used as a teaching reference book for related majors in vocational colleges and computer training classes.
Through practical cases + execution renderings + core code, we will analyze and explore the core underlying principles of JVM, strengthen the implementation of JVM optimization, and teach you step by step the deep principles of Java virtual machines! Portal:
View link

Summarize

There is a lot about JVM. During the communication with the interviewer, you will be asked a variety of questions, but in the end they are all inseparable from the basics. Only when we master the basics can we be able to face various questionings with ease. If you like to learn knowledge by reading books, then you can take a look at the book "A Simple Introduction to Java Virtual Machine: JVM Principles and Practical Combat". If you want to get more Java-related interview questions, you can send me a private message in the background. Let’s learn together and make progress together.

Guess you like

Origin blog.csdn.net/qq_54796785/article/details/133443270