当前位置: 技术问答>java相关
JAVA虚拟机是个什么东东?哪位明白的朋友讲一下。
来源: 互联网 发布时间:2015-08-09
本文导语: 如题。 | Java虚拟机是一个想象中的机器,在实际的计算机上通过软件模拟来实现。Java虚拟机有自己想象中的硬件,如处理器、堆栈、寄存器等,还具有相应的指令系统。 Java语言的一个非常重要...
如题。
|
Java虚拟机是一个想象中的机器,在实际的计算机上通过软件模拟来实现。Java虚拟机有自己想象中的硬件,如处理器、堆栈、寄存器等,还具有相应的指令系统。
Java语言的一个非常重要的特点就是与平台的无关性。而使用Java虚拟机是实现这一特点的关键。一般的高级语言如果要在不同的平台上运行,至少需要编译成不同的目标代码。而引入Java语言虚拟机后,Java语言在不同平台上运行时不需要重新编译。Java语言使用模式Java虚拟机屏蔽了与具体平台相关的信息,使得Java语言编译程序只需生成在Java虚拟机上运行的目标代码(字节码),就可以在多种平台上不加修改地运行。Java虚拟机在执行字节码时,把字节码解释成具体平台上的机器指令执行。
Java语言的一个非常重要的特点就是与平台的无关性。而使用Java虚拟机是实现这一特点的关键。一般的高级语言如果要在不同的平台上运行,至少需要编译成不同的目标代码。而引入Java语言虚拟机后,Java语言在不同平台上运行时不需要重新编译。Java语言使用模式Java虚拟机屏蔽了与具体平台相关的信息,使得Java语言编译程序只需生成在Java虚拟机上运行的目标代码(字节码),就可以在多种平台上不加修改地运行。Java虚拟机在执行字节码时,把字节码解释成具体平台上的机器指令执行。
|
如果你英文可以的话,看看这个教课书上的解释:
The JVM(Java Virtual Machine) consists of a class loader, a class verifer, and a java interpreter that executes the architecture-neutral bytecodes.
The class loader loads .class files from both the java program and the java API for execution by the java interpreter.
After a class is loaded, the verifer checks that the class file is valid java bytecode and does not overflow or underflow the stack. It also ensures that the bytecode does access.
If the class passes verification, it is run by the java interpreter. The JVM also automatically manages memory by performing garbage collection -- the practice of reclaiming memory from objects no longer in use and returning it to the system. Much research focuses on garbage collection algorithms for increasing the performance of java programs in the virtual machine.
The JVM(Java Virtual Machine) consists of a class loader, a class verifer, and a java interpreter that executes the architecture-neutral bytecodes.
The class loader loads .class files from both the java program and the java API for execution by the java interpreter.
After a class is loaded, the verifer checks that the class file is valid java bytecode and does not overflow or underflow the stack. It also ensures that the bytecode does access.
If the class passes verification, it is run by the java interpreter. The JVM also automatically manages memory by performing garbage collection -- the practice of reclaiming memory from objects no longer in use and returning it to the system. Much research focuses on garbage collection algorithms for increasing the performance of java programs in the virtual machine.
|
还有,
The java interpreter may be a software module that interprets the bytecodes one at a time, or it may be a just-in-time (JIT) compiler that turns the architecture-neutral bytecodes into native machine language ofr the host computer. Most implementations of the JVM use a JIT compiler for enhanced performance. In other instances, the interpreter may be implemented in hardware that executes java bytecodes natively. The JVM is presented in Figure 3.12
Figure 3.12
java .class files
||
||
/
class loader
|
V
verifier
|
V
java interpreter
/ ||
|| ||
|| /
host system
The java interpreter may be a software module that interprets the bytecodes one at a time, or it may be a just-in-time (JIT) compiler that turns the architecture-neutral bytecodes into native machine language ofr the host computer. Most implementations of the JVM use a JIT compiler for enhanced performance. In other instances, the interpreter may be implemented in hardware that executes java bytecodes natively. The JVM is presented in Figure 3.12
Figure 3.12
java .class files
||
||
/
class loader
|
V
verifier
|
V
java interpreter
/ ||
|| ||
|| /
host system
|
jvm
java的执行环境 装了jvm才可以运行java
java的执行环境 装了jvm才可以运行java
|
这是JAVA能跨平台的关键,JAVA代码编译后生成BYTECODE,然后通过不同机器上的JVM来运行BYTECODE.
|
You can go to look at the java.sun.com that is best introduction website. this website have more primer for the JVM.