Java Under the Hood: Guide to Java Architecture
Java is based on the concept of Write Once, Run Anywhere (WORA). Java Architecture allows Java programs to run on any device that has a Java Virtual Machine (JVM).
Java Architecture defines how the Java platform works, from writing code to executing it.
It includes:
- Java Language – The programming language you write code in.
- Java Compiler (javac) – Converts .java files into bytecode .class files.
- Java Virtual Machine (JVM) – Executes the bytecode.
- Java Runtime Environment (JRE) – Contains JVM + libraries to run Java applications.
- Java Development Kit (JDK) – Includes JRE + development tools (compiler, debugger, etc.).
⚙️ Java Architecture Components

1. Java Source Code (.java)
- Written by the developer.
- Contains classes, methods, and logic.
2. Java Compiler (javac)
- Converts .java files into bytecode (.class files).
- Ensures code syntax is correct.
3. Bytecode
- Understood by the Java Virtual Machine (JVM).
- Intermediate code.
- Platform-independent.
4. Java Virtual Machine (JVM)
- Executes the bytecode (.class files).
- Manages memory, security, garbage collection, and execution.
- JVM is Platform-Dependent but provides platform independence
- JVM is the heart of the Java platform.
JVM itself is platform-dependent because each operating system requires its own version of the JVM (e.g., JVM for Windows, JVM for Linux, etc.). This means the JVM is specifically built for each platform.
However, the reason Java is platform-independent is that Java source code is compiled into bytecode.
This bytecode is not tied to any platform.
The JVM then runs this bytecode on any platform, making Java programs work on any system, as long as the right JVM is installed.
5. Java Runtime Environment (JRE)
- Contains JVM + libraries.
- Required to run Java applications.
- Like a playground for Java programs
The Java Runtime Environment (JRE) includes a wide range of standard class libraries that provide the core functionality needed to run Java applications. These libraries are part of the Java Standard Edition (Java SE) platform and cover many essential areas of programming. Some of the libraries included in JRE are :
java.util
– Data structures (collections likeList
,Map
,Set
) , date/time, random numbers, and utilitiesjava.awt
– Abstract Window Toolkit for basic GUI components and event handling.java.net
– Classes for sockets, IP addresses, URLs, and HTTP connections.
❗ Important Note
The JRE does not include:
Advanced libraries used for enterprise development like Java EE/Jakarta EE (e.g., javax.servlet, javax.ejb)—those are separate.
JRE provides:
- Memory management
- Allocates memory for objects, stack, heap, etc.
- Security features
- Manages permissions and secure code execution
- Error handling
- Handles runtime exceptions
- Multithreading support
- Allows concurrent execution (e.g., for games, apps)
- Garbage collection
- Frees unused memory automatically
6. Java Development Kit (JDK)
- Contains JRE + tools (e.g., compiler, debugger).
- Required to develop and run Java applications.
- JDK = JRE + Tools(compiler, debugger)
- JDK is Platform-Dependent
JDK includes everything you need to write, compile, and run Java code.
Analogy
Term | Analogy | Description |
---|---|---|
JVM (Java Virtual Machine) | 🖥️ TV Screen | Displays the output — runs Java programs. |
JRE (Java Runtime Environment) | 📺 TV + Remote + Speakers | Everything needed to watch Java programs (JVM + libraries). |
JDK (Java Development Kit) | 🎬 TV + Remote + Camera + Editing Tools | Everything needed to create and watch Java programs (JRE + development tools like compiler). |
Internal Working Mechanism
Let us take an example:
public class Hello {
public static void main(String[] args) {
Message msg = new Message();
msg.sayHello(); }
}
class Message {
public void sayHello() {
System.out.println("Hello from Java!");
}
}
This Java code defines two classes. The Hello
class contains the main
method, which creates an object of the Message
class and calls its sayHello()
method. The sayHello()
method then prints “Hello from Java!” to the console.
So the process of the above demo program when the user clicks on the run button are described below:
i) Compilation
- javac
Hello.java
generates:- Hello.class
- Message.class
ii) Class Loading
- When it encounters
new Message()
, it loadsMessage.class
. - The Class Loader loads
Hello.class
into JVM memory.
iii) Linking
The linking process does 3 major tasks.
a) Verification
- JVM checks if Message.class is valid bytecode.
- Ensures no illegal bytecode instructions are present.
Valid bytecode
Valid bytecode is bytecode that follows Java’s rules and structure, so it can be safely executed by the JVM. For example, you can’t assign a string to an integer variable.
✅ Rule | Explanation |
---|---|
Follow the Java bytecode specification | The .class file must have the correct format (e.g., magic number, constant pool, etc.) |
Have correct instructions and operands | Bytecode must use valid instructions suitable for the data types involved |
Not violate access rules | For example, it must not access private methods or fields from another class |
Not perform illegal memory access | Cannot reference memory locations outside the allowed space |
Pass type checking | For example, you can’t assign a String to an int |
Follow stack discipline | Java uses a stack-based model — bytecode must manage the operand stack properly (push/pop) |
Why is Valid Bytecode Important?
- It ensures security, so no harmful or hacked code gets executed.
- It ensures stability, and your Java program runs safely without crashing.
- It allows platform independence, bytecode can run the same way on all JVMs.
b) Preparation
- JVM allocates memory for static variables.
c) Resolution
- The call
msg.sayHello()
refers toMessage.sayHello()
method. - JVM resolves this symbolic reference to an actual method location in memory.
iv) Execution
- The method
sayHello()
is executed.
Conclusion
Java follows the principle of Write Once, Run Anywhere (WORA) through its robust and layered architecture. This architecture ensures that once Java code is written and compiled into platform-independent bytecode, it can run on any system that has the appropriate Java Virtual Machine (JVM).
Here’s what makes Java architecture powerful:
- The Java Compiler converts source code into bytecode.
- The JVM interprets and runs the bytecode, ensuring platform independence.
- The JRE provides the necessary environment to execute the bytecode.
- The JDK gives developers the tools to write, compile, and debug Java programs.
From writing code to running it, Java’s architecture ensures portability, security, and performance, making it one of the most widely used programming languages across platforms and devices.
Let’s get connected
We can be friends. Find on Facebook, LinkedIn, GitHub, YouTube,
and Instagram.
Contribute: BuyMeACoffee
Contact: Contact Us