简体   繁体   English

为什么我们需要jvm实例来运行我们的Java程序

[英]why we need the jvm instances to run our java program

I'm new to Java. 我是Java新手。 I understand that an instance of the JVM is created whenever a Java program is started. 我知道只要启动Java程序,就会创建JVM实例。 But I wonder why a JVM instance must be created. 但是我想知道为什么必须创建一个JVM实例。

In java an instance is usually created to pin point where the class exist likewise. 在Java中,通常会创建一个实例来确定类也存在的位置。 Is a JVM instance also pointing any classes? JVM实例是否也指向任何类?

I really don't know the purpose of the JVM instance apart from that it is used to run a program. 除了用于运行程序之外,我真的不知道JVM实例的用途。

Could anyone explain me the reason? 谁能解释我的原因?

In Java, the process of writing to executing a program is very similar to C/C++, but with one important difference that allows us to write Java programs that are machine independent . 在Java中,执行程序的编写过程与C / C ++非常相似,但有一个重要的区别,那就是使我们可以编写与机器无关的Java程序

Using an interpreter, all Java programs are compiled to an intermediate level called byte code. 使用解释器,所有Java程序都被编译到称为字节码的中间级别。 We can run the compiled byte code on any computer with the Java runtime environment installed on it. 我们可以在装有Java运行时环境的任何计算机上运行编译后的字节码。

The runtime environment consists of a virtual machine and its supporting code. 运行时环境由虚拟机及其支持代码组成。

May be you can take a look at this thread to solve your doubts: 也许您可以看一下这个线程来解决您的疑问:

How is Java platform-independent when it needs a JVM to run? 需要JVM运行时,Java平台如何独立?

JVM stand for JAVA virtual Machine it is the machine dependent program that will actually read your compiled and convert that code into the machine dependent instructions and thus execute that particular program. JVM代表JAVA虚拟机,它是与机器相关的程序,它将实际读取您编译的内容并将该代码转换为与机器有关的指令,从而执行该特定程序。 May be this will clarify your question 也许这会澄清您的问题

JVM converts your byte code to machine dependent instructions in order for your hardware to understand and execute those instructions. JVM将您的字节码转换为机器相关的指令,以便您的硬件理解并执行这些指令。 JVM comes with JDK(Java Development Kit). JVM随附JDK(Java开发工具包)。

Yes, to answer your question JVM provides a platform for running your code. 是的,回答您的问题JVM提供了运行代码的平台。 Apart from this, it does quite other stuff like memory management, garbage collection, internal thread management and a lot. 除此之外,它还执行其他工作,例如内存管理,垃圾回收,内部线程管理等。

Have a look at this . 看看这个 You will understand. 你会明白的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM