简体   繁体   English

Java虚拟机是否依赖于机器?

[英]Is the Java virtual machine machine dependent?

Is the JVM (Java Virtual Machine) platform dependent? JVM(Java虚拟机)平台是否依赖?

What is the advantage of using the JVM, and having Java be a translated language? 使用JVM并将Java用作翻译语言的优势是什么?

Yes, generally a JVM is platform dependent in the sense that it is implemented for the specific platform. 是的,一般一个 JVM是依赖于平台在这个意义上它是针对特定的平台上实现。

The advantage of using a JVM is that, at least in theory, it makes code written in Java platform agnostic and so the same code could run on any platform without modification to the code. 使用JVM的好处是,至少从理论上讲,它使使用Java平台编写的代码不可知,因此同一代码可以在任何平台上运行而无需修改代码。

There are many advantages to having a virtual machine (such as the Java Virtual Machine - with its' write once, run anywhere promises); 拥有虚拟机有很多优点(例如Java虚拟机-只需编写一次,即可在任何地方运行)。 among them are - 其中有-

  1. Your application becomes operating system independent 您的应用程序独立于操作系统
  2. Your application becomes architecture independent 您的应用程序变得与体系结构无关

In other words, your application becomes (at least somewhat) future-proof as regards to the shifting landscape of competitive vendors. 换句话说,就竞争性供应商的格局变化而言,您的应用程序(至少在某种程度上)变得面向未来。 Still (IMO) the biggest advantage is that Java applications and frameworks run the same on Linux, Mac and Windows. IMO(IMO)的最大优点仍然是Java应用程序和框架在Linux,Mac和Windows上都可以运行。 Although each does need it's own implementation of the Virtual Machine (eg the actual Java Runtime Environment is platform specific, it is available in source form ). 尽管每个人都需要它自己的虚拟机实现(例如,实际的Java Runtime Environment是特定于平台的,但可以以源形式提供 )。

The parts of the JVM that dialogue with the operating system are platform dependant. 与操作系统对话的JVM部分取决于平台。 But Java bytecode is independant, or at least supposed to be (edge cases probably exist). 但是Java字节码是独立的,或者至少应该是字节码(可能存在边缘情况)。

The advantage of the JVM is simply to be able to compile once and be able to run executable bytecode on any platform which is supported. JVM的优点仅仅是能够编译一次并能够在所支持的任何平台上运行可执行字节码。 This is opposed to how things were before where you had to recompile to suit another OS or processor. 这与您不得不重新编译以适合其他OS或处理器之前的情况相反。

Btw, Java is not a translated/interpreted language like PHP or javascript. 顺便说一句,Java不是像PHP或javascript这样的翻译/解释语言。 It's actually compiled with the JVM acting as a middleman or abstraction layer above an operating system. 它实际上是使用JVM作为操作系统上方的中间层或抽象层进行编译的。

JVM itself is not independent. JVM本身不是独立的。 When you download jdk ,you can see that you have to choose you platform at first.You have to get clear your machine and OS type including unix-like ,windows or mac , 32-bit or 64-bit.But we always say that java is a platform-independent programming language,it is because JVM works as a middle-lays between your java application and the underline OS ,thus making java developer can just focus on the same JVM ,ignoring the isomerism of Operating Systems and hardware environments. 当您下载jdk时,您会发现首先必须选择平台。您必须清除机器和操作系统类型,包括unix-like,windows或mac,32位或64位。但是我们总是说Java是与平台无关的编程语言,这是因为JVM充当Java应用程序和下划线OS之间的中间层,因此Java开发人员可以只关注同一JVM,而忽略操作系统和硬件环境的异构性。

JVM is a specification that provides runtime environment in which java bytecode can be executed.

Jvm Interprets your bytecode into Machine Understandable code . Jvm将字节码解释为机器可理解的代码

The JVM performs following operation: JVM执行以下操作:

 - Loads code
 - Verifies code
 - Executes code
 - Provides runtime environment 

To do this a code has to be written, 为此,必须编写代码,
So Implementation of specifications is done here(sun provides mostly). 因此,规范的执行在这里完成(sun提供了大部分)。
This implemetation is JRE . 此实现是JRE

JVM ALSO TELL HOW FOLLOWING THINGS MUST HAPPEN: JVM还告诉必须发生以下事情:

 - Memory area
 - Class file format
 - Register set
 - Garbage-collected heap
 - Fatal error reporting etc.

So Yes JVM strongly platform dependant,find detail working Here JVM Details 因此,是的,JVM非常依赖于平台,请在此处查找详细信息

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

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