Java/J2EE and SOA (324 Blogs) Become a Certified Professional
AWS Global Infrastructure

Programming & Frameworks

Topics Covered
  • C Programming and Data Structures (41 Blogs)
  • Comprehensive Java Course (2 Blogs)
  • Java/J2EE and SOA (323 Blogs)
  • Spring Framework (8 Blogs)
SEE MORE

MI-new-launch

myMock Interview Service for Real Tech Jobs

myMock-widget-banner-bg

What You Should Know About Java Virtual Machine?

Last updated on Aug 26,2019 466 Views
13 / 72 Blog from Java Core Concepts

MI-new-launch

myMock Interview Service for Real Tech Jobs

myMock-mobile-banner-bg

myMock Interview Service for Real Tech Jobs

  • Mock interview in latest tech domains i.e JAVA, AI, DEVOPS,etc
  • Get interviewed by leading tech experts
  • Real time assessment report and video recording

Java programming language has been a giant in the IT industry for a very long time. It has some top-notch concepts that make it better than the rest of the programming language. One such concept is the Java virtual machine, in this article, we will learn about the various aspects of Java virtual machine in detail. Following are the topics discussed in this blog:

What is Java Virtual Machine?

Java virtual machine is a platform-independent abstract machine that provides a runtime environment in which the Java byte code is executed.

It is a part of Java runtime environment that converts the Java bytecode into machine-readable language. The main method that we have in a Java program is actually called by the Java virtual machine.

jvm - java virtual machine - edureka

Why Do We Need Java Virtual Machine?

We need the Java virtual machine for the tasks that it performs which are extremely necessary for any development involving Java. Following are a few tasks that Java virtual machine does.

  • Loads the code
  • Code verification
  • Execution of the code
  • It provides the run-time environment for the applications
  • Memory area
  • Register set
  • Provides a garbage collection heap
  • Reporting of the fatal errors
  • Provides a class file format

With all these operations, the Java virtual machine is an integral part of Java development. Let’s try to understand how it works with the help of the Java virtual machine architecture.

Java Virtual Machine Architecture

Java virtual machine architecture is pretty simple, it has a memory area, a class loader and an execution engine among other components. let us discuss each of them in detail.

architecture- java virtual machine - edureka

ClassLoader

It is a subsystem that is used to load class files. Whenever we run a program in java, it is first loaded by the ClassLoader. the major function includes initialization, linking and loading. The following are the built-in classloaders in Java.

    • Bootstrap ClassLoader – It is the super class of Extension ClassLoader which loads the rt.jar file.

    • Extension ClassLoader – It loads the jar files located in the directory.

    • System/Application ClassLoader – It loads the classfiles from the classpath.

    • Loading Operation – First the classLoader loads the .class files and generates the corresponding data in the binary format which is saved in the method area.

    • Linking Operation – After loading it prepares, verifies and makes resolution. JVM allocates the memory for class variables and initializes the memory to default values. It ensures the correctness of the .class file and when the verification fails, we get the runtime exception error.

    • Initialization – All static variables are assigned with their values defined in the code block in this phase.

JVM Memory

  • Method Area – It stores the structures for each class like the code, field data, runtime constant pool, method data, etc.

  • Heap – Objects are allocated at the runtime in the heap.

  • JVM Language Stacks – It stores local variables and results. It plays an important role in invoking and returning results. Whenever a method is invoked a frame is created and is destroyed as soon as the invocation ends or completes.

  • PC Registers – It has the address or location of the JVMinstruction that is being executed.

  • Native Method Stacks – All the native methods used in the applications are present in the native method stacks.

  • Execution Engine – An execution engine contains a virtual processor, an interpreter and a JIT compiler.

  • Native Method Interface – It is a framework that provides.

Now that we have understood the architecture of the JVM, let’s take a look at the execution process and compilation of code.

Execution Process

The following steps take place while the execution and compilation of a Java code.

  • The main method is stored in a single file and other methods are stored in different files.
  • After the compilation, it will provide corresponding .class files that will have the byte code without any linking, unlike C.
  • During the execution, the class files are verified for any breaches using the Classloader.
  • After this, the bytecode is converted into the corresponding native machine code. This is also the reason why Java is comparatively slower.

Now that we know, how the execution works, let’s take a look at the difference between JDK, JRE, and JVM.

Difference Between JDK, JRE, And JVM

Following are a few important differences between JDK, JVM, and JRE.

  1. JDK stands for Java development kit, and JRE stands for Java runtime environment.
  2. JDK is for development whereas JRE is for the run time environment.
  3. JVM is an essential part of JDK and JRE to run any Java program.
  4. JVM is an integral part of Java programming and provides platform independence.

This brings us to the end of this article where we have learned about the Java virtual machine in detail. I hope you are clear with all that has been shared with you in this tutorial.

If you found this article on “Java Virtual Machine” relevant, check out the Edureka Java Certification Training, a trusted online learning company with a network of more than 250,000 satisfied learners spread across the globe.

We are here to help you with every step on your journey and come up with a curriculum that is designed for students and professionals who want to be a Java Developer. The course is designed to give you a head start into Java programming and train you for both core and advanced Java concepts along with various Java frameworks like Hibernate & Spring.

If you come across any questions, feel free to ask all your questions in the comments section of “Java Virtual Machine” and our team will be glad to answer.

Comments
0 Comments

Browse Categories

webinar REGISTER FOR FREE WEBINAR
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.