Learning the JVM from Scratch series:

Learning from the Ground up ->JVM (Preface)

Learning from the ground up ->JVM (Preface) – Why delay?

JVM (a) : The Java Memory Model (JMM) is not the Java Virtual Machine memory model (JVM) oh!

Learning from the Ground up – JVM part 2: Why does Java Need a JVM (Java Virtual Machine)?

Learning from the Ground up ->JVM (3) : Classloader (1)

Learning from the Ground up ->JVM (4) : Classloader (Middle)

Learning from the ground up ->JVM (5) : Classloader (2)

Learning from the Ground up – JVM part 6: The Relationship between threads and JVMS

Learning from the ground up ->JVM (7) : Runtime Data Area (1)

Learning from the ground up ->JVM (8) : Runtime Data area (2)

Learning from scratch ->JVM (9) : Garbage Collection (1)

Learning from the ground up ->JVM (10) : Garbage Collection (middle)

Learning from scratch ->JVM (11) : Garbage Collection (2)

preface

As we learned more about Java, we turned our attention to the Java Virtual Machine.

We realized that Java’s so-called “Write Once, Run Anywhere” feature was only possible with the JVM. Why, then, does the JVM work this way?

And in the process of exploration, we found that the JVM is not only involved in the “Write Once, Run Anywhere” feature, but also related to the performance of Java programs, so we found that we must go to a deeper understanding of the JVM.

The body of the

If we go straight into the JVM world, we may not really realize what the JVM is as a whole. Maybe we know enough about the details of the JVM, but we still don’t understand the concept as a whole, and we don’t realize what the JVM does for Java. In the whole programming world, if we don’t understand why Java needs the JVM, then we’re not really aware of it.

To understand this, we need to understand what a virtual machine is.

What is a virtual machine? ,

“Virtual machine” is a concept relative to “physical machine”, both of which have code execution capability. The difference is that the execution engine of physical machine is directly built on the level of processor, cache, instruction set and operating system, while the execution engine of virtual machine is realized by software itself. Therefore, the structural relationship between the instruction set and the execution engine can be customized regardless of physical conditions, and the instruction set formats can be executed that are not directly supported by the hardware.

Virtual machine, simply understood, is to allocate a computer into multiple systems with complete computer performance, of course, these independent systems, also known as virtual machines, they all share the hardware resources of this computer.

These virtual machines run on the same computer, but each virtual machine has its own CMOS, hard disk, and operating system.

It can be seen from this, virtual machines have their own independent environment, is isolated from the outside world. To put it bluntly, a virtual machine is like an independent kingdom that can set its own rules without being influenced by external factors.

Why do WE need a Java VIRTUAL machine?

For computer hardware, no matter what the operating system, computer hardware only knows simple binary languages, but different operating systems will have different compilers to compile our high-level languages into binary languages that the computer hardware knows, and then there will be A problem, such as an “A”, The compiled binary of The Windows operating system is 0101, but the compiled binary of the Apple operating system is 1010. As a result, different operating systems may be inconsistent.

And Java is to implement, is “compile once, use everywhere” feature, so if encountered such a situation, is basically impossible to solve.

So Java decided to have its own virtual machine so that all platforms would compile the same way, so that the same Java code would have the same result no matter which operating system it was running on.

So the JVM was born.

What does the JVM do?

The first thing to remember is that the JVM, or Java Virtual Machine, is itself a virtual machine, that is, it has all the features of a virtual machine. It has its own independent environment, in this environment, it is the king of this environment, it sets all the rules of this environment.

So, what rules does the Java virtual machine prescribe?

As we all know, a Java code, after we compile the package, will become a class file bytecode, but the bytecode is not able to run directly above the operating system, because the bytecode instructions is not equivalent to the local machine, it contains only some can be identified by the JVM bytecode instruction, the symbol table, And other supporting information. The JVM, on the other hand, dictates what binaries the bytecode will be translated into and what results will be run.

So, whether you’re writing Java code on a Windows program, whether you’re writing Java code on a MAC system, whether you’re running Java code on a Linux system, whether you’re running Java code on a Windows system, you only compile it once, and when you compile the bytecode code this time, When running on different JVMS on different operating systems, you get the same results, and you get the results you want. In this way, what is known as collective collaborative development can be achieved, where all Java developers, no matter what computer they are using, can end up working on the same project for the same result.

In general, the JVM uses Java bytecode as an intermediate language between the Java user language and the machine language. Implement a generic, machine-independent execution platform.

That is, the JVM is the platform on which Java programs run and the foundation for the underlying implementation of the Java language. Without the JVM, Java programs can’t run properly, nor can they have the “compile once, execute anywhere” feature, which means that the JVM is the founder of the Java empire.

conclusion

Java was created to implement its own features, and because Java became the dominant programming language thanks to the JVM (for one thing), Java today was, in a sense, “created” by the JVM.

As a result, we can well understand the deep bond between the JVM and Java.

Over the decades of programming language development, Java has survived not just by a SINGLE JVM, but by keeping up with The Times and improving, so versioning of the Java language has never stopped.

But the fact that the JVM is the backbone of the Java language has not changed.

Therefore, if we want to have a deeper understanding of the Java language, we must pay attention to the JVM, we must have a deep study of the JVM, so that we can have a deep understanding of Java from development to compilation, and then the entire process of running.

Refer to the blog

Because THIS article was written by me for several days and my computer was turned off and turned on for several times, SO I really can’t remember referring to those blogs. If anyone finds out that my blog has some content borrowed from your blog, please inform me in time and I will post your blog address.