JDK vs JRE vs JVM - AnsuDennis/Java GitHub Wiki

JDK vs JRE vs JVM

JDK = JRE + Compilers + Debuggers

JDK is a software development kit to develop applications in Java.It contains tools for developing, debugging, and monitoring java code. The JDK enables developers to create Java programs that can be executed and run by the JRE and JVM.

  • JDK and JRE: The JDK enables programmers to create core Java programs that can be run by the JRE, which included JVM and class libraries.
  • Class Libraries: It is a group of dynamically loadable libraries that Java program can call at run time.
  • Compilers: It is a Java program that accepts text file of developers and compiles into Java class file. It is the common form of output given by compiler, which contains Java byte code. In Java, the primary compiler is Javac.
  • Debuggers: Debugger is a Java program that lets developers test and debug Java programs.
  • JavaDoc: JavaDoc is documentation made by Sun Microsystems for the Java. JavaDoc can be used generating API documentation in HTML file from the source program

JRE = JVM + Libraries + Other Components (to run applets and other java applications)

JRE is a software bundle which provides Java class libraries with necessary components to run Java code. It has an instance of JVM with it, library classes, and development tools. Once you write and compile Java code, the compiler generates a class file having byte code.

Here are the important components of JRE:

  • Class loaders: The class loader loads various classes that are necessary for running a Java program. JVM uses three class loaders called the bootstrap class loader(loads java core classes), extensions class loader(loads classes from extension directory jre/ext/lib), and system class loader(loads classes from CLASSPATH).System class loader loads files first followed by extensions class loader and finally bootstrap class loader. If class is not found in any of these class loaders ClassNotFound exception will be thrown.
  • Byte code verifier: Byte code verifier verifies the bytecode so that the code doesn't disturb the interpreter.
  • Interpreter: Once the classes get loaded, and the code is verified, the interpreter reads the code line by line.
  • Run-time: Run-time is a system used mainly in programming to describe time period during which a particular program is running.
  • Hardware: Once you compile Java native code, it runs on a specific hardware platform.

JVM = Virtual machine that run the Java bytecode and make java portable. It is platform independent.

JVM executes Java byte code and provides an environment for executing it. Software development tools are not included in JVM.

Here are the important components of JVM:

  • Class Loader: The class loader is a subsystem used for loading class files. It performs three major functions viz. Loading, Linking, and Initialization.
  • Method Area: JVM Method Area stores structure of class like metadata, the code for Java methods, and the constant runtime pool.
  • Heap: All the Objects, arrays, and instance variables are stored in a heap. This memory is shared across multiple threads.
  • JVM language Stacks: Java language Stacks store local variables, and its partial results. Each and every thread has its own JVM language stack, created concurrently as the thread is created. A new frame is created when method is invoked, and it is removed when method invocation process is complete.
  • PC Registers: PC registers store the address of the Java virtual machine instruction, which is currently executing. In Java, each thread has its separate PC register.
  • Native Method Stacks: Native method stacks hold the instruction of native code depends on the native library. It allocates memory on native heaps or uses any type of stack.
  • Execution Engine: It is a type of software that is used to test software, hardware, or complete systems. The test execution engine never carries any information about the tested product.
  • Native Method interface: The Native Method Interface is a programming framework. It allows Java code, which is running in a JVM to call by libraries and native applications.
  • Native Method Libraries: Native Libraries is a collection of the Native Libraries (C, C++), which are needed by the Execution Engine.