In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail what is the principle of virtual machine jvm in java. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Once upon a time, when we were still first acquainted with Hello World, we never knew that the magical language Java, when executing our code, did not directly deliver the Java code we wrote to the bottom of the operating system for parsing and compilation, but used JDK to compile the Java code, compiled into dotClass files, and transferred the dotClass files to JRE. (dotClass is actually .class)
Jre is the JavaRunTimeEnvironment,java runtime environment, because here, there is a secret weapon of Java, namely JVM! Jvm is an important core of JRE. It can be said that JVM is the soul of JRE, the art of controlling the body and executing the code. JRE contains almost all the class libraries needed for Jvm calls. It can be said that jvm is the driver of jre, the driver of the whole JDK, and the driver of the whole Java!
Hello, everyone. I'm fntp. Today, let's talk briefly about why Java needs JVM. Today's topic is very big, but limited to space, we just have a simple chat!
Quick understanding of JVM
JVM is the Java virtual machine, that is, the meaning of Java Virtual Machine, the word "virtual". Basically, we can see that in order to achieve many functions on the operating system, we need a complete architecture and strong execution standard! Is this a bit similar to the "operating system"? JVM is actually a Java instruction execution specification, and it is this standard that constitutes JVM. When we learn Java, we all know that there is JDK,JRE. When we learn deeply, we will find that there is also the fairy JVM.
Let's first sort out the relationship between these things:
Let me give you the answer first: JDK contains JRE, and JRE contains JVM.
JDK we all know is the java development kit, the so-called toolkit, but also because its main role is to provide jvm with additional class library tools, such as compiling Java files javac binary programs, these are stored in the bin directory, isn't it strange that many programs are installed with a bin directory? Because this bin means binary, which is the abbreviation bin of binary, that is, the directory of binaries.
Similar gadgets include Java (.exe binaries in the bin directory), jar and other files in addition to Javac. Okay, what about jre? JRE provides an execution environment for Java programs. With jre, our java programs can be run in browsers. Why do you need jre? Because of our jvm, we all know that java is compiled and run everywhere. How do you do this?
This is actually the work of jre, our jre Chinese is not the java runtime environment, yes, we know that java is running in jvm, and the java runtime environment is the running environment of jvm. As the saying goes, a clever housewife cannot make bricks without rice, and it is impossible to execute all java programs with jvm alone. We also need to come from some underlying class libraries written in c language. At this time, the left and right sides of jre are very obvious. Jre provides almost all the dependent class libraries for jvm, so you can really compile and run everywhere!
Jvm can execute java programs, is it the direct execution of java files? No, as we said, the Java and the operating system do not transfer .java files directly to the operating system for processing, but compile .java files into .class files through javac binaries, also known as bytecode files, bytecode files directly to the operating system for execution? No, let's take a look at the difference between ordinary program execution and Java program execution:
The loading process of the Java program:
What does it mean to tell you that the bytecode file is unknown to the operating system? bytecode files also need to be loaded into machine code by jvm, that is, Opcode operation code (which is not entirely understood for the time being), and translated into machine code, that is, a language that the operating system can understand before the operating system goes back to execute this java program. What is this? it's actually a bit like the black box test we often talk about. The whole process is invisible, we can only see that the java specification code we wrote is executed by the operating system!
We say that after jvm recognizes the bytecode file, it translates the bytecode instructions and translates them to the operating system, thus controlling the operating system to perform the corresponding functions. Therefore, when it comes to translation, we have to briefly talk about the ways and methods of JVM's translation of bytecode files. Jvm translates bytecode in two different ways, one is immediate loading method, the other is interpretation and execution. Interpretation execution translates the opcode and operands in the bytecode file into op instructions, that is, machine code, while instant loading is triggered under specific circumstances, and the bytecode is translated into machine code and executed.
This is the end of the article on "what is the principle of virtual machine jvm in java". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 223
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.