Skip to main content

Java Introduction

JVM, JRE, JDK

JVM (Java Virtual Machine)

Imagine the Java Virtual Machine (JVM) like a magic engine for running computer programs. Even though you can't touch or see it, it's there to make sure your Java programs work. That's why it is called a virtual machine because it doesn't physically exist.

This magic engine follows a set of rules (a specification) and creates a special space (runtime environment) where your Java programs can come to life. What's cool is that it can also understand programs written in other languages, as long as they are translated into a special code called Java bytecode.

Now, here's the interesting part: the magic engine, the JVM, can work on all sorts of computers and devices. But, there's a catch. The way it works can be a bit different depending on whether you're using a Windows computer, a Mac, or something else. This is where terms like JVM, JRE, and JDK come in.

JVM is like the big idea, the blueprint. JRE (Java Runtime Environment) is like the actual package with everything needed to run Java programs. And JDK (Java Development Kit) is the super toolbox with extra tools for building and fixing those programs.

So, Java, thanks to this magic engine (JVM), can run on pretty much anything, even if the behind-the-scenes stuff varies a bit. It's like having a translator (JVM) that speaks many computer languages and can understand them all, making sure your programs run smoothly on different devices!

Working of JVM

JRE (Java Runtime Environment)

JRE stands for Java Runtime Environment. Think of it like a toolkit for building and running programs in Java. It's a bunch of software tools that help make sure your Java applications run smoothly.

Unlike the invisible Java Virtual Machine (JVM), JRE is the real deal — it physically exists on your computer. Inside this toolkit are special files and libraries eg. ,jar files that the JVM uses when your Java program is running.

And get this: it's not only made by Sun Microsystems; other companies also create their own versions of this toolkit. It's like having different brands of the same handy toolkit, all working to make sure your Java programs work on your computer. Cool, right?

Java Runtime Envrionment

JDK (Java Development kit)

So, JDK stands for Java Development Kit. It's like a special toolbox for computer wizards who want to create cool things with Java. This toolbox is not just a bunch of code; it's a real thing you can have on your computer.

Inside this toolbox, there's something called JRE, which is like the essentials pack for running Java programs. But the JDK is even cooler because it doesn't just help run programs, it helps build them too!

Now, Oracle, the company that made Java, has a few different versions of Java for different purposes, like building regular software (Standard Edition), big business applications (Enterprise Edition), and small device programs (Micro Edition). The JDK is like a master key that can work with any of these.

Inside the JDK toolbox, there's a mini Java Virtual Machine (JVM), which is like a little computer just for your Java creations. There are also tools like an interpreter (java), a compiler (javac), and other gadgets that make the whole process of creating a Java application super smooth. It's like having a super kit for turning your creative ideas into awesome Java programs!

Java Development Kit

Difference between JDK, JRE and JVM.

JDK JRE JVM
Toolkit used to create Java applications.
Besides containing the JRE (Java Runtime Environment),
it also includes various development tools like compilers,
JavaDoc, and Java Debugger.
It's like the engine that runs Java programs.
It includes Java class libraries, the Java
Virtual Machine (JVM), and other components
needed to execute Java applications.
Think of it as a computer within your computer.
It interprets and executes Java bytecode.
It has three roles: a specification (describing what a JVM should do),
an implementation (the actual program that follows the specification),
and an instance (when it's running and executing Java code).
Primarily used for developing and executing code. Mainly responsible for creating the environment
needed to run code.
Specifies and provides implementations to JRE.
Platform dependent : Needs different
versions of JDK for different platforms.
Platform dependent Platform-independent, which means it
can run on various types of computers.
Equipped with tools for developing,
debugging, and monitoring Java applications.
Lacks tools like compilers or debuggers;
it mainly contains libraries and supporting files for the JVM.
Doesn't include software development tools.
Combines Java Runtime Environment
(JRE) with development tools.
Combines Java Virtual Machine (JVM)
with libraries to run applications.
Provides only the runtime environment for
executing Java bytecode.

How Java Achieves Platform Independence?

Imagine you're telling a computer what to do, but this computer could be a Windows laptop, a Mac, or any other kind of computer. Java is like a superhero language that helps your instructions work on all these different computers.

  1. Write Once, Run Anywhere (WORA):
    • It's like writing a secret code that only Java understands. You write this code once, and it can be used anywhere without changing it. So, it's like having a universal remote for different types of TVs.
  2. Compilation to Bytecode:
    • Instead of making a special code for each type of computer, Java turns your code into something called "bytecode." It's like turning your instructions into a language that a magical translator (Java Virtual Machine or JVM) can understand.
  3. Java Virtual Machine (JVM):
    • Think of the JVM as a friendly imaginary computer inside your real computer. It takes the bytecode and makes sure your instructions work on your specific computer, no matter if it's a Windows, Mac, or something else. It's like having a language translator that speaks the computer's language.
  4. Platform-Specific JVMs:
    • Different computers have different versions of the translator (JVM) because they speak slightly different computer languages. But the good news is, the magic translator understands the bytecode, so your Java instructions work everywhere without you having to change anything.

So, when people say "Write Once, Run Anywhere," they mean you can write your instructions in Java, and they will magically work on any computer, thanks to the special translator (JVM) that speaks the computer's language. It's like having a superpower for making computer programs that work everywhere!