Technology Explained

What Is the Java Virtual Machine & How Does It Work?

Simon Slangen 02-04-2012

The Java Virtual Machine (JVM) is a real name dropper when you’re programming in Java. Contrary to what the name indicates, the Java Virtual Machine can be encountered in relation with other programming languages as well.


In general, it’s not necessary to know what the Java Virtual Machine is, or even what it does, to be able to program in Java. On the other hand, familiarizing yourself with the inner workings of a machine does help to increase your understanding and overall insight.

This article brushes over the idea of the Java Virtual Machine, what it does for you, and some of the most important pros and cons. Although I’ve tried to keep it simple, and there is definitely more advanced literature on the subject, a rudimentary understanding of Java and programming is expected.

High-Level Languages

The semantics of a programming language are designed to be close to our natural language, while staying concise and easy to interpret for a machine. As you probably know, the programming language is wholly different from machine code, the set of instructions a computer uses to construct and run a program. This we call high-level languages; one or multiple levels of abstraction from the machine code.

Before it is able to run, high-level code must first be interpreted. A lot of programming interfaces compile in advance (AOT compilation) for a specific platform. This makes the program more efficient at runtime, but far less compatible with different platforms. Java, in contrast, works with an intermediate language called Java bytecode and the Java Virtual Machine.

JVM & Java Bytecode

When your Java project builds, it translates the source code (contained in *.java source files) to Java bytecode (most often contained in *.class files). This takes your high-level code one step closer to machine code, but not quite there yet. This bytecode is a collection of compact instructions; easier for a machine to interpret, but less readable.


When you run a Java application on your computer, cellphone, or any other Java-enabled platform, you essentially pass this Java bytecode to the Java Virtual Machine. The interpreter in the Java Virtual Machine usually starts compiling the entire bytecode at runtime, following the principles of so-called just-in-time compilation. This makes for the typical, albeit often slight delay when opening a Java application, but generally enhances the program performance compared to interpreted compilation.

java virtual machine

The main advantage of this system is the increased compatibility. Since your applications run in a virtual machine instead of directly on your hardware, the developer can program and build their application once, which can then be executed on every device with an implementation of the Java Virtual Machine. This principle has given birth to the Java slogan: “Write once, run everywhere.”

Pro: Compatibility & Increased Security

Apart from code compatibility, the Java Virtual Machine comes with other benefits. One of the most important of those is the relative security of Java programs as a result of the Java Virtual Machine. Security, meaning that a program running in a virtual machine is far less likely to disrupt the user’s operating system, or corrupt data files, if errors occur.


Con: Different JVM Implementations & Debugging

One of the main criticisms voiced against the code compatibility and the Java Virtual Machine is due to the many different implementations of the latter. You see, the Java Virtual Machine is not one piece of software. Oracle, the owners of Java, have their implementation of the Java Virtual Machine, but other people can make theirs if it satisfies various practical and contractual claims.

These different implementations mean that your code may run smoothly on one Java Virtual Machine, but crash and burn on another. Although, in practice, you can write your code once and run it everywhere, more complex code sometimes still has to be debugged in different Java Virtual Machine implementations to ensure correct operation.

Do you have any experience of working with the Java Virtual Machine?  If so, is there anything I missed out here that should be mentioned?

Image Credit: MichaelawDcoetzee


Related topics: Java, Programming.

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Atheesh Rathnaweera
    May 3, 2018 at 3:16 am

    Good article...Anyone can understand this easily...Thank you very much..

  2. Neha
    January 27, 2018 at 9:39 am

    Great article ! Even someone with a very basic programming concepts can understand this.

  3. Nikolaos Vamvoukakis
    January 24, 2017 at 12:36 pm

    really useful

  4. Nikolaos Vamvoukakis
    January 24, 2017 at 12:36 pm

    thank you really useful

  5. Katy
    September 2, 2016 at 3:00 pm

    Thank you for your article. I begin to get a handle on the subject!

  6. Ahmad Minwer
    May 21, 2016 at 9:05 am

    Thank you Simon.

  7. karunakarreddy a
    January 5, 2015 at 7:54 am

    when it loading a class jvm what are the factors identifies

  8. shaurya boogie
    June 23, 2012 at 7:49 pm

    Hey dude, will you please write an article on windows mango vs android 4 vs iOS[later version]. It will be a great favour.

    • Simon Slangen
      June 29, 2012 at 3:13 pm

      Thanks for the tip. Maybe we will! :-)

  9. Z.B. Manfred
    April 6, 2012 at 3:37 am

    Whoa, Doc Brown, this stuff is heavy. I thought a Java Virtual Machine meant an early prototype for Mr. Coffee. :-D

  10. LSk
    April 5, 2012 at 8:33 am

    Can anyone please help me to install in IE9. From where do i download the latest JVM.
    Thanks a lot.

  11. renato
    April 3, 2012 at 12:34 am

    The Java Virtual Machine ideally will not allow any harm to come to the computer because it can't affect the operating system and acts as if it is a separate computer. Thus, if a malicious Java program were to crash the Java Virtual Machine the operating system would remain stable, at least in most cases.

    • Jeffery Fabish
      April 3, 2012 at 7:58 am

      That's actually not true. Despite the name, when a Java applet is running it still has access to your documents. It's not like a virtual machine, such as Virtualbox. All the virtual machine does is convert bytecode (instructions for an intermediate compiler, or JIT) into CPU-specific code, so that a java application can be "programmed once, ran anywhere" and is only dependent on the interpreters existence.

      • Simon Slangen
        April 5, 2012 at 5:45 pm

        The Java apps run in/through the JVM, which gives them a higher level of abstraction. This makes the program 'safer' in that a crash shouldn't propagate to, or interfere with the host OS. However, these Java applications still have read/write capabilities. An application is still capable that way to screw up important files on your computer.