How Java Works
JVM, JRE, JDK, WORA principle, Compilation to Execution flow
- Understand what Java is and its key characteristics
- Explain WORA (Write Once, Run Anywhere)
- Differentiate between JVM, JRE, and JDK
- Trace the complete flow from source code to execution
All Visual Image Notes
36 SlidesSlide 1 of 36 — Java Definition

*Java Basics to Advanced | Lecture 2*
Table of Contents
- Java Editions: JSE, JEE, JME
- How Java Code Flows: Compilation to Execution
- Writing Your First Java Program
- Platform Dependence vs. Platform Independence
- Summary Tables and Diagrams
- Common Mistakes
- Best Practices
- Interview Notes
- Practice Questions
- Quick Revision Summary
1. What is Java?
Overview
Java is one of the most widely used programming languages in the world. Before diving into syntax and programs, it is essential to understand what Java is, why it exists, and what makes it special.
Definition
Java
is a platform-independent, object-oriented programming language and computing platform first released by Sun Microsystems in 1995 (now maintained by Oracle).
When asked "What is Java?" in an interview or exam, a complete answer is:
"Java is a platform-independent, highly popular object-oriented programming language. Its biggest advantage is portability, which is described by the principle WORA — Write Once, Run Anywhere."
Key Characteristics of Java
| Characteristic | Description |
|---|---|
| Platform Independent | Java programs can run on any OS without modification |
| Object-Oriented | Built around the OOP principles: Inheritance, Polymorphism, Encapsulation, Abstraction |
| Portable | Compiled bytecode runs on any system with a JVM |
| Strongly Typed | All variables must be declared with a type |
| Compiled + Interpreted | Source code is compiled to bytecode, then interpreted/JIT-compiled at runtime |
| Automatic Memory Management | Built-in Garbage Collector handles memory |
| Multi-threaded | Built-in support for concurrent programming |
OOP Features in Java
Java is built on the four pillars of Object-Oriented Programming:
1┌────────────────────────────────────────────┐2│ Object-Oriented Programming │3│ │4│ 1. Inheritance 2. Polymorphism │5│ 3. Encapsulation 4. Abstraction │6└────────────────────────────────────────────┘These will be covered in dedicated lectures, but they form the foundation of every Java program.
2. WORA Write Once, Run Anywhere
Overview
The single biggest advantage of Java is portability. This is captured in the famous acronym:
WORA = Write Once, Run Anywhere
What WORA Means
Imagine you write a Java program on your mobile phone. Without any modifications, that same program can be run on:
- A Windows desktop
- A Mac laptop
- A Linux server
- Any other device
This is not possible in languages like C or C++, where you need to recompile the source code for each target platform separately. Java achieves this through a two-step process involving bytecode and the JVM.
Why WORA Matters
The key insight: you compile the source code once, and the resulting bytecode can be run anywhere a JVM is installed.
3. Three Core Components: JVM, JRE, JDK
Overview
Java's architecture is built on three nested components. Understanding these is fundamental — they are asked about in almost every Java interview.
3.1 JVM Java Virtual Machine
Definition
JVM (Java Virtual Machine)
is an abstract machine — it does not physically exist as hardware. It is a software-based virtual machine that provides a runtime environment in which Java bytecode can be executed.
The word abstract here means: there is no physical machine called JVM. It is a software specification/implementation that behaves like a machine.
What JVM Does
The JVM sits between the bytecode (.class file) and the underlying hardware/OS. Its job is to:
- Accept bytecode as input
- Convert bytecode to machine code using its built-in JIT Compiler
- Execute the machine code on the host hardware
JIT Compiler Just-In-Time Compiler
Inside the JVM lives a special compiler called the JIT (Just-In-Time) Compiler.
JIT Compiler
translates bytecode into native machine code at runtime, just before each piece of code is executed. This is different from traditional compilers that translate the entire source code before any execution begins.
| Compiler Type | When it compiles | Input | Output |
|---|---|---|---|
| javac (Java Compiler) | Before runtime | .java source file | .class bytecode |
| JIT Compiler (inside JVM) | At runtime | .class bytecode | Native machine code |
Is JVM Platform Independent or Dependent?
This is a critical concept that confuses many beginners:
This means:
- If you are on Windows, you need the Windows JVM
- If you are on macOS, you need the macOS JVM
- If you are on Linux, you need the Linux JVM
Each operating system has its own specific JVM implementation. But all JVMs understand the same bytecode. That is the secret of WORA.
Memory and Execution in JVM
The JVM manages several memory areas internally:
| Memory Area | Purpose |
|---|---|
| Method Area | Stores class-level data: class names, method bytecode, static variables |
| Heap | Runtime memory for all objects (created with new) |
| Stack | Each thread has its own stack; stores local variables, method call frames |
| PC Register | Program Counter — tracks which instruction is currently executing |
| Native Method Stack | For native (non-Java) code calls |
We will explore these in detail when we cover memory management in future lectures.
3.2 JRE Java Runtime Environment
Definition
JRE (Java Runtime Environment)
is the environment required to run Java programs. It contains: 1. JVM — to execute bytecode 2. Class Libraries — pre-written Java code that programs can use
1JRE = JVM + Class LibrariesClass Libraries
Java ships with a massive collection of pre-written, ready-to-use code called class libraries (also called the Java API or standard library).
Examples used in the lecture:
1// From java.lang package (Math library)2int result = Math.abs(-10); // Returns 103
4// From java.util package (Arrays library)5int[] arr = {5, 3, 1, 4, 2};6Arrays.sort(arr); // Sorts the array: [1, 2, 3, 4, 5]These libraries are already compiled and bundled with JRE. When your bytecode uses them, JVM resolves them at runtime using the class libraries bundled in JRE.
What You Can and Cannot Do with Just JRE
| Task | JRE Only |
|---|---|
Run a Java program (from .class bytecode) | ✅ Yes |
| Write Java source code | ❌ No |
| Compile Java source code | ❌ No |
| Debug Java programs | ❌ No |
How JRE Resolves Libraries at Runtime
Consider this scenario:
- You write Java code that calls
Arrays.sort(arr) - You compile it →
.classbytecode is created - JVM starts executing the bytecode
- JVM encounters the
Arrays.sortcall - JVM looks up
java.util.Arraysfrom the class libraries in JRE - The library code is loaded and executed
- Execution continues
This is why JRE needs both JVM (to run bytecode) AND class libraries (to resolve library calls).
3.3 JDK Java Development Kit
Definition
JDK (Java Development Kit)
is the full package for developing Java programs. It includes everything in JRE plus additional development tools.
1JDK = JRE + Programming Language + Compiler (javac) + Debugger + Other Tools2JDK = JVM + Class Libraries + Programming Language + Compiler + DebuggerWhat JDK Provides
| Component | Tool | Purpose |
|---|---|---|
| Programming Language | Java syntax, keywords | Write Java source code |
| Compiler | javac | Compiles .java → .class (bytecode) |
| Debugger | jdb | Debug Java programs step by step |
| JRE | (included) | Run compiled programs |
| JVM | (via JRE) | Execute bytecode |
| Class Libraries | (via JRE) | Standard library access |
| Other Tools | jar, javadoc, etc. | Package and document code |
Nesting Relationship
Platform Dependence Summary
| Component | Platform Dependent? |
|---|---|
| JVM | ✅ Yes — different for each OS |
| JRE | ✅ Yes — different for each OS |
| JDK | ✅ Yes — different for each OS |
.java source file | ✅ Yes — needs compilation |
.class bytecode | ❌ No — runs on any JVM (WORA) |
Comparison Table: JVM vs JRE vs JDK
| Feature | JVM | JRE | JDK |
|---|---|---|---|
| Full Form | Java Virtual Machine | Java Runtime Environment | Java Development Kit |
| Purpose | Execute bytecode | Run Java programs | Develop + Run Java programs |
| Contains | JIT Compiler, Memory Mgmt | JVM + Class Libraries | JRE + Compiler + Debugger + Tools |
Can run .class files? | ✅ (core function) | ✅ | ✅ |
Can compile .java files? | ❌ | ❌ | ✅ |
| Platform Dependent? | ✅ Yes | ✅ Yes | ✅ Yes |
| Who needs it? | Part of JRE | End users running Java apps | Developers |
How to Download JDK
Steps:
- Go to https://www.oracle.com/java/technologies/downloads/
- Choose the version (e.g., Java 8, Java 11, Java 17, Java 21 LTS)
- Download the installer for your OS (Windows x64, macOS, Linux)
- Install it following the installer instructions
After installation, verify from terminal/command prompt:
1java -versionExpected output (example for Java 17):
1java version "17.0.x" 2023-xx-xx LTS2Java(TM) SE Runtime Environment (build 17.0.x+x-LTS)3Java HotSpot(TM) 64-Bit Server VM (build 17.0.x+x-LTS, mixed mode, sharing)4. Java Editions: JSE, JEE, JME
Overview
Java comes in three major editions, each targeting a different type of application development.
The Three Editions
Detailed Breakdown
JSE Java Standard Edition
JSE (Java Standard Edition)
is what most people refer to as "Core Java". It is the foundation of all Java development.
Everything covered in a typical Java course — classes, objects, inheritance, polymorphism, collections, multithreading — is part of JSE.
What it includes:
- Core language features
- Basic class libraries (
java.lang,java.util,java.io, etc.) - Collections Framework
- Multithreading
- Exception Handling
- I/O Streams
- Generics
JEE Java Enterprise Edition
JEE (Java Enterprise Edition)
= JSE + additional enterprise-grade APIs.
Used for building large-scale, distributed applications such as:
- E-commerce platforms
- Banking systems
- Enterprise resource planning (ERP) systems
Additional features in JEE:
- Servlets — Handle HTTP requests/responses (web layer)
- JSP (JavaServer Pages) — Dynamic web pages with Java
- Transactional API —
commit,rollbackfor database transactions - Persistence API (JPA) — ORM for relational databases
- EJB (Enterprise JavaBeans) — Business logic components
- JMS (Java Message Service) — Messaging between applications
JME Java Micro/Mobile Edition
JME (Java Micro Edition / Java Mobile Edition)
provides APIs for building applications on resource-constrained devices.
Originally designed for:
- Mobile phones (feature phones)
- Embedded systems
- IoT devices
Edition Comparison Table
| Edition | Full Name | Also Called | Target | Key Features |
|---|---|---|---|---|
| JSE | Java Standard Edition | Core Java | Desktop / General | Classes, OOP, Collections, Threads |
| JEE | Java Enterprise Edition | Java EE / Jakarta EE | Enterprise / Web | Servlets, JSP, JPA, Transactions |
| JME | Java Micro Edition | Java ME / Jakarta EE | Mobile / Embedded | Mobile APIs, Resource-constrained |
5. How Java Code Flows: Compilation to Execution
Overview
Understanding the complete flow from writing code to getting output is essential. This is the mechanism behind WORA.
The Complete Flow
Step-by-Step Breakdown
Step 1: Write Source Code
- You write Java code in a
.javafile - Example:
Employee.java
Step 2: Compile
1javac Employee.java- The
javaccompiler (part of JDK) reads the.javafile - It checks for syntax errors
- It translates the source code into bytecode
Step 3: Bytecode Generated
- A new file
Employee.classis created - This
.classfile contains bytecode — not machine code, not source code - Bytecode is a compact, intermediate representation
Step 4: JVM Reads Bytecode
1java Employee- The
javacommand starts the JVM - JVM reads
Employee.class(bytecode) - JVM calls the
mainmethod to start execution
Step 5: JIT Compilation
- Inside the JVM, the JIT Compiler converts bytecode → native machine code
- This happens at runtime, line by line (or method by method)
Step 6: CPU Executes
- The CPU runs the native machine code
- Output is produced
File Extensions Reference
| File | Extension | Contains | Created By |
|---|---|---|---|
| Source File | .java | Human-readable Java source code | Developer |
| Bytecode File | .class | Platform-independent bytecode | javac compiler |
Key Insight: Why Bytecode Instead of Machine Code?
Traditional languages like C/C++ compile directly to machine code. The problem: machine code is platform-specific. Code compiled on Windows won't run on Linux.
Java's solution: compile to bytecode (a neutral intermediate format), then let each platform's JVM translate bytecode to its own machine code at runtime.
1C/C++ Approach:2Source → Machine Code (Windows) → ❌ Cannot run on Linux3
4Java Approach:5Source → Bytecode → JVM(Windows) → Machine Code(Windows) ✅6 → JVM(Linux) → Machine Code(Linux) ✅7 → JVM(macOS) → Machine Code(macOS) ✅6. Writing Your First Java Program
Overview
Let's build a complete Java program from scratch, understanding every single element.
6.1 Class Structure
In Java, everything lives inside a class. A class can contain:
1Class2├── Variables (Fields/Attributes)3├── Methods (Functions/Behaviors)4├── Constructors (Special initialization methods)5└── Nested/Inner ClassesWe will explore each of these deeply in future lectures. For now, let's focus on the minimum required structure.
File Naming Rule
| File Name | Class Name | Valid? |
|---|---|---|
Employee.java | Employee | ✅ Yes |
employee.java | Employee | ❌ No |
Employee.java | Emp | ❌ No |
MyClass.java | MyClass | ✅ Yes |
Also:
.java file can have only ONE public class.You can have multiple classes in one file, but only one of them can be declared public, and it must match the filename.
Basic Class Skeleton
1public class Employee {2 // variables, methods, constructors go here3}6.2 The `main` Method
What Is the `main` Method?
Themainmethod is the entry point of every Java application. When you run a Java program, the JVM looks for and calls themainmethod first to begin execution.
No matter how many classes, files, or methods exist in your project — execution always begins from main.
Syntax
1public static void main(String[] args) {2 // Your code here3}Keyword-by-Keyword Breakdown
| Keyword | Meaning |
|---|---|
public | Access modifier — the method can be called from anywhere (including from outside the package, which is what JVM needs) |
static | The method belongs to the class itself, not to any object — JVM can call it without creating an object first |
void | Return type — this method does not return any value |
main | The name of the method — JVM specifically looks for this name |
String[] args | Parameter — an array of Strings for command-line arguments passed by the user at runtime |
Why `public`?
JVM needs to call main from outside the class (from outside the package, technically). If main were private, JVM couldn't access it. Making it public means anyone — including JVM — can call it.
Why `static`?
Normally, to call a method in Java, you need to create an object of the class first:
1// Normal method — needs an object2Employee emp = new Employee(); // create object3emp.someMethod(); // call through objectBut main is special — JVM needs to call it before any objects are created. If main were not static, JVM would need to create an Employee object first, but it doesn't know how to do that automatically.
static means the method belongs to the class, not an instance (object). JVM can call it directly:
1// Static method — no object needed2Employee.main(args); // JVM calls it like this internallyWhy `void`?
void means the method returns nothing. The main method doesn't need to return a value to JVM — it just runs the program. When main finishes, the program ends.
Why `String[] args`?
This allows users to pass command-line arguments when running the program:
1java Employee arg1 arg2 arg3These arguments are received in the args array:
args[0]="arg1"args[1]="arg2"args[2]="arg3"
We will explore this in detail in a future lecture.
JVM and `main` The Connection
6.3 Comments in Java
Comments are lines that the compiler ignores. They are purely for human readers — they do not affect program execution.
Types of Comments
◆ 1. Single-Line Comment
1// This is a single-line comment2int a = 10; // This comment is after code on the same lineUse // — everything after it on that line is ignored by the compiler.
◆ 2. Multi-Line Comment
1/* This is a multi-line comment.2 It can span multiple lines.3 The compiler ignores everything between the opening and closing. */4int a = 10;Use / ... / — everything between the / and / is ignored.
◆ 3. Javadoc Comment (special multi-line)
1/**2 * This is a Javadoc comment.3 * Used to generate API documentation automatically.4 * @param name The name of the employee5 * @return void6 */7public void setName(String name) {8 // ...9}Used with the javadoc tool to auto-generate HTML documentation.
Comment Comparison Table
| Type | Syntax | Spans Multiple Lines? | Use Case |
|---|---|---|---|
| Single-line | // comment | ❌ No | Quick notes, end-of-line remarks |
| Multi-line | / comment / | ✅ Yes | Longer explanations, disabling code blocks |
| Javadoc | /* comment / | ✅ Yes | API documentation generation |
6.4 Variables and Output
Declaring a Variable
1int a = -10;| Part | Meaning |
|---|---|
int | Data type — integer (whole number) |
a | Variable name |
= | Assignment operator |
-10 | Value assigned |
; | Statement terminator (required in Java) |
Printing to Console
1System.out.println("This is my first program and output of a is " + a);| Part | Meaning |
|---|---|
System | A built-in class in java.lang package |
out | A static field of System — represents the standard output stream (console) |
println | Method that prints the argument and then moves to a new line |
"..." | String literal — text in double quotes |
+ | String concatenation operator — joins text with variable value |
a | Variable whose value is appended to the string |
`println` vs `print`
| Method | Behavior |
|---|---|
System.out.println(x) | Prints x and moves to the next line |
System.out.print(x) | Prints x but stays on the same line |
6.5 Compiling and Running
The Complete First Program
1public class Employee {2
3 public static void main(String[] args) {4
5 // Single-line comment — compiler ignores this6 7 /* Multi-line comment8 This is also ignored by compiler */9
10 int a = -10;11
12 System.out.println("This is my first program and output of a is " + a);13 }14}Step-by-Step Execution
Line 1: public class Employee {
- Declares a public class named
Employee - File must be named
Employee.java
Line 3: public static void main(String[] args) {
- Declares the entry point method
- JVM will call this when the program starts
Lines 5-8: Comments
- Completely ignored by compiler
- No effect on execution
Line 10: int a = -10;
- Declares an integer variable
aand assigns it the value-10 - Memory is allocated on the stack for variable
a
Line 12: System.out.println(...)
- Evaluates the expression
"This is my first program and output of a is " + a - The
+operator convertsa(which is-10) to a String"-10"and concatenates - Result:
"This is my first program and output of a is -10" printlnprints this string to the console and moves to a new line
Output
1This is my first program and output of a is -10Compiling from Terminal
1# Step 1: Navigate to the directory containing Employee.java2cd /path/to/your/project3
4# Step 2: Compile the source file5javac Employee.java6
7# After this, Employee.class appears in the same directory8# (You can verify by listing files: ls or dir)9
10# Step 3: Run the compiled bytecode11java Employeejavac Employee.java (include the .java extension)
When running: java Employee (do NOT include .class extension)What Happens in the File System
Before compilation:
1project/2└── Employee.java ← source file (you wrote this)After compilation:
1project/2├── Employee.java ← source file (unchanged)3└── Employee.class ← bytecode (generated by javac)Critical Observation: `.java` vs `.class`
Employee.java but do NOT recompile, the output will NOT change.
JVM reads ONLY the .class file (bytecode), NOT the .java file.Demonstration:
1# Initial state: a = -102java Employee3# Output: This is my first program and output of a is -104
5# Now change the source: a = -11 (save Employee.java)6# But DO NOT recompile7
8java Employee9# Output: This is my first program and output of a is -10 ← STILL -10!10# Because Employee.class hasn't been updated yet11
12# Now recompile13javac Employee.java14
15java Employee16# Output: This is my first program and output of a is -11 ← NOW -11This demonstrates perfectly that JVM executes bytecode (.class), not source code (.java).
7. Platform Dependence vs. Platform Independence
Summary Diagram
The Magic Explained
- You write
Employee.javaon any machine - You compile it once →
Employee.class(bytecode) - The
.classfile is platform independent — it is the same on every OS - You take the
.classfile to any system that has a JVM - That JVM (which is platform-specific) translates the bytecode to native machine code
- The program runs — same output, any platform
This is WORA in action.
8. Summary Tables and Diagrams
Complete Architecture Mind Map
Java Execution Flow Summary
9. Common Mistakes
Mistake 1: File Name Doesn't Match Class Name
1// File: emp.java ← WRONG2public class Employee { // Class name is Employee but file is emp.java3 // ...4}Error: class Employee is public, should be declared in a file named Employee.java
Fix:
1// File: Employee.java ← CORRECT2public class Employee {3 // ...4}Mistake 2: Running Without Compiling First
1java Employee # ← WRONG — running before compilingError: Error: Could not find or load main class Employee
Fix:
1javac Employee.java # compile first2java Employee # then runMistake 3: Including `.class` Extension When Running
1java Employee.class # ← WRONGError: Error: Could not find or load main class Employee.class
Fix:
1java Employee # ← CORRECT — no extensionMistake 4: Forgetting to Recompile After Editing
1# Edited Employee.java (changed value from -10 to 100)2java Employee # ← runs old .class file, shows -10 not 100Fix: Always recompile after editing source code:
1javac Employee.java # recompile2java Employee # run updated versionMistake 5: Wrong `main` Method Signature
1// WRONG — various incorrect signatures2static void main(String[] args) { } // missing public3public void main(String[] args) { } // missing static4public static void Main(String[] args) { } // capital M — wrong name5public static int main(String[] args) { } // wrong return type6public static void main() { } // missing String[] argsFix: The signature must be exactly:
1public static void main(String[] args) { }void main() (without public static and String[] args) works as a preview feature for simple programs. But for standard Java, always use the full signature.Mistake 6: Confusing Platform Independence of JVM vs Bytecode
10. Best Practices
- Always name your file exactly as your public class — Java requires this.
- Always recompile after changes — JVM runs bytecode, not source code.
- Use meaningful variable names —
employeeAgeis better thana. - Always use comments for non-obvious code sections.
- Use Java's class libraries — don't reinvent the wheel.
Arrays.sort(),Math.abs(), etc. are already tested and optimized. - Download JDK from official Oracle website — avoid unofficial sources.
- Keep one public class per file — Java enforces this; it's also good organization.
- Understand that
mainis the entry point — structure your program's logic to flow naturally frommain.
11. Interview Notes
Commonly Asked Questions
Q1: What is Java?
Answer: Java is a platform-independent, object-oriented programming language. Its biggest advantage is portability, captured by WORA — Write Once, Run Anywhere. This is achieved through bytecode and JVM.
Q2: What is the difference between JVM, JRE, and JDK?
Answer:
- JVM — Abstract machine that executes bytecode. Contains JIT compiler. Platform dependent.
- JRE — JVM + Class Libraries. Can run Java programs. Cannot develop them.
- JDK — JRE + Compiler (javac) + Debugger. Required for development.
Q3: Is JVM platform independent?
Answer: No. JVM is platform dependent. You need a specific JVM for each OS (Windows, macOS, Linux). However, Java bytecode (.class files) is platform independent — the same bytecode can run on any JVM.
Q4: What is bytecode?
Answer: Bytecode is the intermediate, platform-independent code generated by the Java compiler (javac) from .java source files. It is stored in .class files and is the input to the JVM. The JVM's JIT compiler converts it to native machine code at runtime.
Q5: Why is `main` method `public static void`?
Answer:
public— JVM must be able to call it from outside the class/packagestatic— JVM calls it without creating an object of the class firstvoid— It doesn't return any value to JVM
Q6: What is WORA?
Answer: WORA = Write Once, Run Anywhere. It means you write Java source code once, compile it to bytecode once, and that bytecode can run on any system that has a JVM — regardless of the underlying OS or hardware.
Q7: What is the difference between `.java` and `.class` files?
Answer:
.java— Source file written by the developer in Java syntax.class— Bytecode file generated byjavaccompiler; this is what JVM reads and executes
Q8: What is JIT Compiler?
Answer: JIT (Just-In-Time) Compiler is a component inside the JVM that converts bytecode to native machine code at runtime. Unlike the javac compiler (which compiles before execution), JIT compiles during execution, enabling performance optimizations.
Q9: What happens if you change `.java` but don't recompile?
Answer: The output does not change. JVM reads only the .class (bytecode) file. Changes to .java have no effect until you recompile using javac.
Q10: What are the three Java editions?
Answer:
- JSE — Java Standard Edition (Core Java) — what developers learn/use daily
- JEE — Java Enterprise Edition — adds Servlets, JSP, JPA, Transactions for large apps
- JME — Java Micro/Mobile Edition — for mobile and resource-constrained devices (now Jakarta EE)
12. Practice Questions
Easy
- What does WORA stand for? What makes Java WORA?
- What is the file extension of a Java source file? A bytecode file?
- What command compiles a Java file named
Hello.java? - What command runs a compiled Java class named
Hello? - What is the role of the
mainmethod? - Which component of JDK is used for compilation?
- Can you run a Java program with just JRE? Can you write and compile one?
Medium
- Explain the complete flow from writing Java code to seeing output on the console.
- Why is JVM platform dependent but Java programs are platform independent?
- What is the difference between JRE and JDK? When would you install each?
- Why must
mainbestatic? What would happen if it weren't? - What does the JIT compiler do and when does it run?
- You modified
Employee.javaand saved it. Without recompiling, what willjava Employeeoutput?
Hard
- A colleague claims "JVM is platform independent because Java is platform independent." How would you correct this misunderstanding with a clear explanation?
- Explain why Java's two-step compilation (source → bytecode → machine code) is both a strength and potentially a performance concern, and how JIT mitigates the concern.
- What would happen at runtime if your bytecode calls
Arrays.sort()but thejava.utillibrary is not available? Where in JVM's architecture does library resolution happen? - Design a diagram showing how a Java program written on a Linux machine can be run on Windows without any changes to the source or bytecode.
- If JVM is platform dependent, how does Oracle (or OpenJDK) provide JVM for so many different platforms? What does each platform-specific JVM implementation do?
13. Quick Revision Summary
1☕ JAVA OVERVIEW — KEY POINTS2
3✅ Java = Platform Independent + OOP Language4✅ WORA = Write Once, Run Anywhere = Portability5
6📦 THREE COMPONENTS:7 JVM = Executes bytecode (platform DEPENDENT)8 JRE = JVM + Class Libraries (can run programs)9 JDK = JRE + Compiler + Debugger (can develop programs)10
11📁 FILE TYPES:12 .java = Source code (you write this)13 .class = Bytecode (compiler generates this)14
15🔄 EXECUTION FLOW:16 .java → javac → .class → JVM → JIT → Machine Code → Output17
18📱 THREE EDITIONS:19 JSE = Core Java (what we learn)20 JEE = Enterprise (Servlets, JPA, Transactions)21 JME = Mobile/Embedded (Jakarta EE)22
23⚠️ CRITICAL RULES:24 • File name = Public class name25 • One public class per file26 • main = entry point (JVM calls it first)27 • public static void main(String[] args)28 • Always recompile after editing source code29
30💡 INTERVIEW TRICK:31 • JVM is platform DEPENDENT32 • Bytecode (.class) is platform INDEPENDENT33 • Java (the language/program) is platform INDEPENDENTEnd of Chapter — Java Overview
Study Guide generated from: Java Basics to Advanced — Lecture 2: Java Overview
Practice & Implement
Apply what you learned in How Java Works
Write a Java program that prints 'Hello, Java!' and also prints the Java version using `System.getProperty("java.version")`.
Hello, Java!
Mastery check
How well can you recall this?
Finished this lesson?