This is the seventh day of my participation in the August More text Challenge. For details, see: August More Text Challenge

JVM is the most core knowledge point of Java learning, but also the most complex test point in the interview. I highly recommend Deep Understanding of the Java Virtual Machine: Advanced Features and Best Practices for the JVM (3rd edition) by Zhiming Zhou. Read this book several times, and you’ll find it rewarding each time. (You can use wechat to read and buy, touch 🐟 at work)

Below is a map I compiled, leaving out some of the stuff (such as bytecode technology, modularization systems, compilation and optimization) that is so complicated that it should be covered in a future article. I have uploaded the source file of this map to Github, welcome to take your own, the original map address is: JVM

Why do YOU need to learn about the Java Virtual Machine

The Java Virtual Machine is transparent to Java developers, and we only need to know the use of Java’s core class libraries and third-party apis to focus on business code. However, the Java virtual machine is not omnipotent, there are always some unexpected situations that need to be solved by ourselves, such as:

  • Applications need some performance tuning, and the JVM provides a number of configuration parameters to meet performance requirements in different scenarios.
  • Java programmers have given control of memory to the Java virtual Machine, and when memory leaks and overflows occur, it can be extremely difficult to troubleshoot errors and fix problems without understanding how the virtual machine is using memory.

So let’s relive the classics together. Overall, the Java virtual Machine is a lot to learn, and it’s hard to learn it all, but it’s ok to know some of the basics, tuning parameters, and tools.

How does Java work

This is a classic interview question, and it’s the beginning of the JVM question. The execution process is as follows:

In general, our written.Java files (source files) are compiled by the compiler into.class files (bytecode), which are then loaded into memory by the JVM’s classloader. The interpreter interprets the bytecode files into machine instructions that the computer can recognize and that the operating system can execute. Inside the Java virtual machine, the.class file is loaded and placed in the method area, and the virtual machine executes the code in the method area when it actually runs. The Java virtual machine also divides memory into heaps and stacks to store runtime data.

In fact, this also shows why Java is cross-platform, achieving its boast of “Write Once, Run Anywhere”. Because of the Existence of the Java Virtual Machine, information at the operating system level is masked, Java programs can run unmodified on multiple platforms simply by generating the object code (bytecode) that the Java virtual Machine runs on.