Introduction to JDK JRE JVM
In Java documentation, we frequently come across the terms JVM, JRE, and JDK. A clear understanding of these terms is essential to grasp their usage and differences. Let’s examine each of these terms in detail and then identify their differences.
Java Virtual Machine (JVM) is a run-time system that executes Java bytecode. The JVM is like a virtual computer that can perform a set of compiled instructions and manipulate memory locations. When a Java compiler compiles the source code, it generates a highly optimised set of instructions called bytecode in a .class file. The JVM interprets these bytecode instructions and converts them to machine-specific code for execution.
JVMs are implemented for different hardware platforms and Operating Systems, such as Windows, IBM Mainframes, Linux, Mac OS, and so on. Though the implementation details of the JVMs are different, they are all capable of executing the same bytecode.
Key Features of the JVM
Some of the critical features of JVM are:
A Java program that is converted to bytecode executes the same way on different platforms. This is possible because only the implementation details of the JVMs differ from one platform to another. All the JVM implementations are capable of interpreting and executing the same bytecode. Therefore, there is no need to compile each Java program into the native code of individual machines. In this way, Java supports the powerful “write once, run anywhere” feature.
JVM is a controlled environment that provides the necessary memory for a program to execute. Because the JVM provides memory management and garbage collection functionality, it can prevent applications from illegally accessing memory and causing harm outside of the run-time system.
Suitability for the Web:
The portability offered through JVM is a considerable advantage for web-based programs because there is no need to create different versions of an application for different platforms. The web connects systems with many different hardware and software environments. As long as a system implements the required JVM, any Java program that is compiled into bytecode can be executed on it.
Fast Execution Time:
JVMs include a Just-in-Time (JIT) compiler to speed up execution times. A JIT compiler is a part of a JVM that converts portions of bytecode into machine code at the time of execution. This on-demand translation of bytecode reduces the overall execution time of Java programs.
The Java Development Kit (JDK) is a software development environment that you can use to develop and execute Java applications. It includes the JRE and a set of programming tools, such as a Java compiler, interpreter, appletviewer, and document viewer. The JDK is implemented through the Java SE, Java EE, or Java ME platforms.
Some of the programming tools available in the JDK are:
Java: A loader for Java programs that interprets the Java bytecode in .class files and converts them to machine code.
Javac: A compiler that converts Java source code to bytecode.
appletviewer: A tool that is used to run and debug Java applets.
Jar: An archiver that packages related class libraries into a single file.
javafxpackager: A tool that is used for packaging and signing JavaFX applications.
Javadoc: A document generator.
The Java Runtime Environment (JRE) is a part of the JDK that includes a JVM, core classes, and several libraries that support application development. Though the JRE is available as part of the JDK, you can also download and use it separately.
Some of the components of the JRE are:
JVM that includes Java HotSpot Client and Server VMs.
Util and lang base libraries that include lang and util, Collections, Preferences API, Regular Expressions, Logging, and so on.
Deployment technologies such as Java Web Start and Java Plug-in.
UI toolkits such as AWT, Java 2D, Swing, Sound, Image IO, and so on.
Integration libraries such as JDBC, IDL, RMI, and so on.
Other base libraries such as Beans, Networking, Security, Serialization, international support, IO, and so on.
Differences between JDK JRE JVM
JDK is a superset that contains JRE, whereas JRE is a superset that includes JVM.
JVM does not compile Java source code whereas JRE includes a compiler for Java source code.
JVM does not include software development tools, whereas JDK and JRE provide several tools for application development.
JDK includes compilers and debuggers, whereas JRE and JVM do not include these tools.