Programming





What is Java Virtual Machine(JVM)?

What is Java Virtual Machine(JVM)?


by Administrator | 20-Mar-2020
Java

Tags:  Java Runtime Environment  Java Virtual Machine  Java Development Kit

Share: 


JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides a runtime environment in which java byte code can be executed. It is a process running in the machine virtually. The task of JVM is to provide the support to execute java application and to manage the resources that are required for the execution of the application.

When we install a java package, it contains 2 things, Java Runtime Environment (JRE), Java Development Kit (JDK). The JRE provides runtime support for Java applications. The JDK provides the Java Compiler and other development tools. The JDK includes the JRE. Both the JRE and the JDK include a Java Virtual Machine (JVM). This is the application that executes a Java program. A Java program requires a JVM to run on a particular platform. JVMs are available for many hardware and software platforms (i.e. JVM is platform dependent).

The JVM performs four main tasks:

  1. Loads code
  2. Verifies code
  3. Executes code
  4. Provides runtime environment

JVM provides definitions for the following:

  1. Memory area
  2. Class file format
  3. Register set
  4. Garbage-collected heap
  5. Fatal error reporting etc.

Internal Architecture of JVM
Let's understand the internal architecture of JVM. It contains a classloader, memory area, execution engine, etc.

jvm-architecture

  1. Classloader: Classloader is a subsystem of JVM that is used to load class files.
  2. Class(Method) Area: Class (Method) Area stores per-class structures such as the runtime constant pool, field and method data, the code for methods.
  3. Heap: It is the runtime data area in which objects are allocated.
  4. Stack: Java Stack store frames. It holds local variables and partial results, and plays a part in method invocation and return. Each thread has a private JVM stack created at the same time as thread. A new frame is created each time a method is invoked. A frame is destroyed when its method invocation completes.
  5. Program Counter Register: It contains the address of the JVM instruction currently being executed.
  6. Native Method Stack: It contains all the native methods used in the application.
  7. Execution Engine: It contains:
    1. A virtual processor
    2. Interpreter: Read the bytecode stream then execute the instructions.
      It will be used to read the byte code, to verify that and execute that after converting it into machine code.
    3. Just-In-Time(JIT) compiler: It is used to improve performance. JIT compiles parts of the byte code that have similar functionality at the same time, and hence reduces the amount of time needed for compilation. Compiler refers to a translator from the instruction set of a Java virtual machine (JVM) to the instruction set of a specific CPU. Because of the interpreter, the byte code will be verified line-by-line, instead of using an interpreter to read the byte code Sun has provided JIT compiler. It is the installer file by using that java software will be installed in your machine.

Questions and Answers

  1. What is the difference between JDK and JRE? JDK is a bundle of software that you can use to develop Java-based software. JDK contains various development tools like the Java source compilers, bundling and deployment tools, debuggers, development libraries, etc. JRE is an implementation of the Java Virtual Machine which actually executes Java programs. JRE (Java Runtime Environment) It is the collection of java interpreter (JVM), native libraries, java libraries, etc. it will be used to provide some environment that will support to execute the java application. We can access the JRE in the file system.
  2. Can the Java interpreter is used for the execution of the source code? Yes
  3. On successful compilation, a file with the .class extension is created? Yes
  4. Can the Java source code be created in a Notepad editor? Yes
  5. The Java Program is enclosed in a class definition? Yes
  6. What is a compilation unit? A compilation unit is a Java Source Code file.
  7. Is Empty .java file a valid source file? Yes, an empty .java file is a perfectly valid source file.
  8. Can a .java file contain more than one java class? Yes, a .java file contains more than one java class, provided at the most one of them is a public class.

Comments:


There are no comments.

Enter a new Comment:










Copyright Šprgrmmng. All rights reserved.