Java Virtual Machine (JVM), Difference JDK, JRE & JVM – Core Java

By Chaitanya Singh | Filed Under: Learn Java

Java is a high level programming language. A program written in high level language cannot be run on any machine directly. First, it needs to be translated into that particular machine language. The javac compiler does this thing, it takes java program (.java file containing source code) and translates it into machine code (referred as byte code or .class file).

Java Virtual Machine (JVM) is a virtual machine that resides in the real machine (your computer) and the machine language for JVM is byte code. This makes it easier for compiler as it has to generate byte code for JVM rather than different machine code for each type of machine. JVM executes the byte code generated by compiler and produce output. JVM is the one that makes java platform independent.

So, now we understood that the primary function of JVM is to execute the byte code produced by compiler. Each operating system has different JVM, however the output they produce after execution of byte code is same across all operating systems. Which means that the byte code generated on Windows can be run on Mac OS and vice versa. That is why we call java as platform independent language. The same thing can be seen in the diagram below:

So to summarise everything: The Java Virtual machine (JVM) is the virtual machine that runs on actual machine (your computer) and executes Java byte code. The JVM doesn’t understand Java source code, that’s why we need to have javac compiler that compiles *.java files to obtain *.class files that contain the byte codes understood by the JVM. JVM makes java portable (write once, run anywhere). Each operating system has different JVM, however the output they produce after execution of byte code is same across all operating systems.

JVM Architecture

Lets see how JVM works:
Class Loader: The class loader reads the .class file and save the byte code in the method area.

Method Area: There is only one method area in a JVM which is shared among all the classes. This holds the class level information of each .class file.

Heap: Heap is a part of JVM memory where objects are allocated. JVM creates a Class object for each .class file.

Stack: Stack is a also a part of JVM memory but unlike Heap, it is used for storing temporary variables.

PC Registers: This keeps the track of which instruction has been executed and which one is going to be executed. Since instructions are executed by threads, each thread has a separate PC register.

Native Method stack: A native method can access the runtime data areas of the virtual machine.

Native Method interface: It enables java code to call or be called by native applications. Native applications are programs that are specific to the hardware and OS of a system.

Garbage collection: A class instance is explicitly created by the java code and after use it is automatically destroyed by garbage collection for memory management.

JVM Vs JRE Vs JDK

JRE: JRE is the environment within which the java virtual machine runs. JRE contains Java virtual Machine(JVM), class libraries, and other files excluding development tools such as compiler and debugger.
Which means you can run the code in JRE but you can’t develop and compile the code in JRE.

JVM: As we discussed above, JVM runs the program by using class, libraries and files provided by JRE.
JDK: JDK is a superset of JRE, it contains everything that JRE has along with development tools such as compiler, debugger etc.

https://beginnersbook.com/2013/05/jvm/

原文地址:https://www.cnblogs.com/feng9exe/p/12074699.html

时间: 2024-10-03 09:12:46

Java Virtual Machine (JVM), Difference JDK, JRE & JVM – Core Java的相关文章

JVM Specification 9th Edition (4) Chapter 3. Compiling for the Java Virtual Machine

Chapter 3. Compiling for the Java Virtual Machine Table of Contents 3.1. Format of Examples 3.2. Use of Constants, Local Variables, and Control Constructs 3.3. Arithmetic 3.4. Accessing the Run-Time Constant Pool 3.5. More Control Examples 3.6. Recei

JVM Specification 9th Edition (2) Chapter 2. The Structure of the Java Virtual Machine

Chapter 2. The Structure of the Java Virtual Machine 内容列表 2.1. The class File Format (class文件的格式) 2.2. Data Types (数据类型) 2.3. Primitive Types and Values (原始数据类型和值) 2.3.1. Integral Types and Values 2.3.2. Floating-Point Types, Value Sets, and Values 2

JVMS Specification(2)-Compiling for the Java Virtual Machine

Subsections 2       Compiling for the Java Virtual Machine 2.1        Format of Examples 2.2        Use of Constants, Local Variables, and Control Constructs 2.3        Arithmetic 2.4        Accessing the Runtime Constant Pool 2.5        More Control

Java初学者不得不知的概念,JDK,JRE,JVM的区别?

JVM(Java Virtual Machine Java虚拟机) 可以理解为是一个虚拟出来的计算机,具备着计算机的基本运算方式, 它主要负责将java程序生成的字节码文件解释成具体系统平台上的机器指令. 让具体平台如window运行这些Java程序. JRE(Java Runtime Environment Java运行环境) 包括Java虚拟机(JVM Java Virtual Machine)和Java程序所需的核心类库等, 如果想要运行一个开发好的Java程序,计算机中只需要安装JRE即

Java初学者不得不知的概念,JDK,JRE,JVM的区别?(转)

JVM(Java Virtual Machine Java虚拟机)可以理解为是一个虚拟出来的计算机,具备着计算机的基本运算方式,它主要负责将java程序生成的字节码文件解释成具体系统平台上的机器指令.让具体平台如window运行这些Java程序. JRE(Java Runtime Environment Java运行环境)包括Java虚拟机(JVM Java Virtual Machine)和Java程序所需的核心类库等,如果想要运行一个开发好的Java程序,计算机中只需要安装JRE即可. JD

JVM(Java Virtual Machine)

Java语言的一个非常重要的特点就是与平台的无关性.而使用Java虚拟机是实现这一特点的关键.一般的高级语言如果要在不同的平台上运行,至少需要编译成不同的目标代码.而引入Java语言虚拟机后,Java语言在不同平台上运行时不需要重新编译.Java语言使用Java虚拟机屏蔽了与具体平台相关的信息,使得Java语言编译程序只需生成在Java虚拟机上运行的目标代码(字节码),就可以在多种平台上不加修改地运行.Java虚拟机在执行字节码时,把字节码解释成具体平台上的机器指令执行.这就是Java的能够“一

A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No Java virtual machine was found after searching the following locations: /usr/local/eclipse/

linux系统下jdk是已经安装好的情况之下软件出现 A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No Java virtual machine was found after searching the following locations: /usr/local/eclipse/jre/bin/java java in yo

Ubuntu Eclipse启动时报错:A Java RunTime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No java virtual machine was found after searching the following locations:

此问题起于我在Ubuntu1004上装了两个版本的eclipse:Galieo+helios:卸载前者后出现启动不了eclipse的问题:在网上找了下,可以按如下过程进行解决: Eclipse 3.6 在 Ubuntu 10.04 下会出现一个很奇怪的现象,我没有经过测试,无法确定是Ubuntu 10.04 还是 JDK 还是 Eclipse本身造成的. 这个现象是: 可以在终端顺利启动Eclipse,但是鼠标双击,或者用起动器启动就会出现如下的内容: A Java RunTime Enviro

关于 JDK jre jvm

JDK 全名是 JAVA development kit  是JAVA语言的软件开发工具 包:是整个JAVA开发的核心,没有JDK的话,无法编译Java程序,如果想只运行Java程序,要确保已安装相应的JRE. JDK包含的基本组件包括: javac – 编译器,将源程序转成字节码: jar – 打包工具,将相关的类文件打包成一个文件: javadoc – 文档生成器,从源码注释中提取文档: jdb – debugger,查错工具: java – 运行编译后的java程序(.class后缀的):