ArticleslgStudy

computer science

Java virtual machine

Java virtual machine is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Java virtual machine rather than just read about it. In short: A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages, referred to as JVM languages, that are also compiled to Java bytecode. The JVM is detailed by a specification that formally describes what is required in a JVM implementation.

Java virtual machine — main illustration
Java virtual machine — illustration

Key takeaways

  • Java virtual machine belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Java virtual machine to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Java virtual machine from memory before moving on to harder problems.

Reference excerpt

A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages, referred to as JVM languages, that are also compiled to Java bytecode. The JVM is detailed by a specification that formally describes what is required in a JVM implementation. Having a specification ensures interoperability of Java programs across different implementations so that program authors using the Java Development Kit (JDK) need not worry about idiosyncrasies of the underlying hardware platform. The JVM reference implementation is developed by the OpenJDK project as open source code and includes a JIT compiler called HotSpot. The commercially supported Java releases available from Oracle are based on the OpenJDK runtime. Eclipse OpenJ9 is another open source JVM for OpenJDK.

JVM specification The Java virtual machine is an abstract (virtual) computer defined by a specification. It is a part of the Java Runtime Environment. The garbage collection algorithm used and any internal optimization of the Java virtual machine instructions (their translation into machine code) are not specified. The main reason for this omission is to not unnecessarily constrain implementers. Any Java application can be run only inside some concrete implementation of the abstract specification of the Java virtual machine. Starting with Java Platform, Standard Edition (J2SE) 5.0, changes to the JVM specification have been developed under the Java Community Process as JSR 924. As of 2006, changes to the specification to support changes proposed to the class file format (JSR 202) are being done as a maintenance release of JSR 924. The specification for the JVM was published as the blue book, whose preface states:

We intend that this specification should sufficiently document the Java Virtual Machine to make possible compatible clean-room implementations. Oracle provides tests that verify the proper operation of implementations of the Java Virtual Machine. The most commonly used Java virtual machine is Oracle's HotSpot. Oracle owns the Java trademark and may allow its use to certify implementation suites as fully compatible with Oracle's specification.

Garbage collectors

Garbage collectors available in Java OpenJDKs virtual machine (JVM) include:

Serial Parallel CMS (Concurrent Mark Sweep) G1 (Garbage-First) ZGC (Z Garbage Collector) Epsilon Shenandoah GenZGC (Generational ZGC) GenShen (Generational Shenandoah) IBM Metronome (only in IBM OpenJDK) SAP (only in SAP OpenJDK) Azul C4 (Continuously Concurrent Compacting Collector) (only in Azul Systems OpenJDK)

Java's design philosophy revolves around the assumption of a garbage collector. Unlike languages such as C++ and Rust, deterministic memory management through a delete keyword (as in C++) is not possible. Even introducing such a feature is not possible, due to a lack of ownership semantics. In fact, the sun.misc.Unsafe and java.lang.foreign (see Foreign Function and Memory API) allocate/deallocate memory outside the Java heap. Due to Java primarily using heap-based allocation, objects are stored as references, and deletion would result in dangling pointers.

… excerpt ends here. Continue reading the full article.

Illustrations

Java virtual machine: Overview of a Java virtual machine (JVM) architecture based on The Java Virtual Machine Specification Java SE 7 Edition
Overview of a Java virtual machine (JVM) architecture based on The Java Virtual Machine Specification Java SE 7 Edition

Worked examples

Example 1 — a first encounter with Java virtual machine

Start with the simplest possible case. Write down what Java virtual machine claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Java virtual machine before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Java virtual machine ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Java virtual machine

In research
Java virtual machine appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Java virtual machine in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Java virtual machine is common in secondary-school and first-year university syllabi. It links to neighbouring topics Java (programming language), Java platform software, Java specification requests, so understanding it makes those chapters shorter.
In everyday life
Look for Java virtual machine outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Java virtual machine” →

How to study Java virtual machine in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Java virtual machine means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Java virtual machine out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Java virtual machine in simple terms?

A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages, referred to as JVM languages, that are also compiled to Java bytecode. The JVM is detailed by a specification that formally describes what is required in a…

Why does Java virtual machine matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Java virtual machine?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Java virtual machine.

Tags

  • Java (programming language)
  • Java platform software
  • Java specification requests
  • Java virtual machine
  • Stack-based virtual machines

Keep exploring