Java
What is Java?
Java is a high-level, class-based, object-oriented, platform-independent programming
language developed by James Gosling and his team at Sun Microsystems in 1995. It was
later acquired by Oracle Corporation in 2010.
Java follows the principle:
Write Once, Run Anywhere (WORA)
Unlike languages such as C and C++, Java programs are not compiled directly into machine
code. Instead, the Java compiler converts source code into Bytecode, which is executed by
the Java Virtual Machine (JVM). This allows the same Java program to run on any operating
system that has a compatible JVM.
Why was Java Developed?
Before Java, software developed for one operating system usually required modifications to
run on another. Java solved this problem by introducing the Java Virtual Machine (JVM),
which acts as a bridge between the compiled Java program and the operating system.
Goals of Java
Platform Independence
Simplicity
Security
Robustness
Object-Oriented Design
Network-Centric Programming
High Performance
Portability
Java Features
1. Platform Independent ⭐⭐⭐⭐⭐
Java follows the Write Once, Run Anywhere (WORA) principle.
The source code is compiled into Bytecode, which can execute on any platform with a JVM.
Windows
│
Linux ├──► JVM ───► Runs Same Bytecode
│
macOS
Interview Point
Java is platform-independent, but the JVM itself is platform-dependent because each
operating system requires its own JVM implementation.
2. Object-Oriented ⭐⭐⭐⭐⭐
Java is based on the concept of objects, which combine data (attributes) and behavior
(methods).
The four pillars of OOP are:
Encapsulation
Inheritance
Polymorphism
Abstraction
Example:
class Student {
String name;
void study() {
[Link]("Studying...");
}
}
3. Simple ⭐⭐⭐⭐☆
Java removes many complex features found in C++, such as:
Pointer arithmetic
Multiple inheritance through classes
Operator overloading
Manual memory management
This makes Java easier to learn, write, and maintain.
4. Robust ⭐⭐⭐⭐⭐
A language is called robust if it is reliable and less prone to runtime failures.
Java achieves robustness through:
Strong type checking
Automatic Garbage Collection
Exception Handling
Memory management
Bytecode verification
5. Secure ⭐⭐⭐⭐⭐
Java provides multiple layers of security:
No direct pointer manipulation
Bytecode Verifier
Class Loader
Security Manager (legacy concept)
Runtime access checks
These features reduce common issues such as memory corruption and unauthorized code
execution.
6. Multithreaded ⭐⭐⭐⭐☆
Java allows multiple threads to execute concurrently within the same program.
Example:
Downloading a file while playing music.
A web server handling multiple client requests simultaneously.
7. High Performance ⭐⭐⭐⭐☆
Although Java is an interpreted language, performance is improved using the Just-In-Time
(JIT) Compiler, which converts frequently executed bytecode into native machine code.
8. Portable ⭐⭐⭐⭐☆
Java programs produce the same results across different hardware architectures because:
Primitive data type sizes are fixed.
Bytecode is platform-neutral.
JVM abstracts hardware differences.
9. Distributed ⭐⭐⭐☆☆
Java provides built-in support for developing distributed applications using technologies
such as:
Sockets
Remote Method Invocation (RMI)
Web Services
Networking APIs
10. Dynamic ⭐⭐⭐☆☆
Java can load classes during runtime using the Class Loader, making applications modular
and extensible.
Real-World Applications of Java
Domain Examples
Enterprise Software Banking Systems, ERP, CRM
Android Development Native Android Apps
Web Development Spring Boot, Servlets, JSP
Cloud Computing AWS, Azure, Google Cloud
Big Data Apache Hadoop
Financial Systems Trading Platforms
Scientific Applications Research Tools
IoT Embedded & Smart Devices
Why is Java Popular?
Easy to learn and write
Huge ecosystem and libraries
Excellent community support
Strong object-oriented foundation
Cross-platform compatibility
High demand in industry
Preferred language for backend development
Frequently asked in placement interviews
💼 Placement Corner
Top Interview Questions
Q1. Why is Java platform-independent?
Answer: Java source code is compiled into Bytecode, which runs on the JVM. Since different
operating systems have their own JVM implementations, the same .class file can execute
without recompilation.
Q2. Is JVM platform-independent?
Answer: No. The JVM is platform-dependent, while Java programs are platform-
independent.
Q3. Why is Java called object-oriented and not purely object-oriented?
Answer: Java is not purely object-oriented because it supports primitive data types (int,
char, boolean, etc.), which are not objects.
Q4. Why doesn't Java support pointers?
Answer: To improve security, simplicity, and memory safety. Java manages memory
automatically through the JVM and Garbage Collector.
Q5. What is WORA?
Answer: Write Once, Run Anywhere—a Java program compiled once can run on any
platform with a compatible JVM.
What is JVM (Java Virtual Machine)?
The Java Virtual Machine (JVM) is an abstract (virtual) machine that provides the runtime
environment for executing Java bytecode (.class files).
It acts as a bridge between the Java program and the operating system.
Responsibilities of JVM
Loads Java classes into memory.
Verifies bytecode before execution.
Executes Java bytecode.
Allocates and manages memory.
Performs Garbage Collection (GC).
Handles exceptions.
Ensures platform independence.
Remember: JVM does not compile Java code. It only executes Bytecode.
What is JRE (Java Runtime Environment)?
The Java Runtime Environment (JRE) provides everything required to run a Java application.
It consists of:
JVM
Core Java Libraries
Supporting Runtime Files
JRE
│
├── JVM
├── Java Libraries
└── Runtime Files
Used By
✔ End Users
✔ Systems that only execute Java programs
What is JDK (Java Development Kit)?
The Java Development Kit (JDK) is a complete software development package used to
develop, compile, debug, and run Java programs.
It contains:
JRE
Compiler (javac)
Java Launcher (java)
Javadoc Tool
Jar Tool
Debugger
Other Development Utilities
JDK
│
├── JRE
│ ├── JVM
│ ├── Libraries
│ └── Runtime Files
│
├── javac
├── java
├── jar
├── javadoc
├── jdb
└── Other Tools
Used By
✔ Java Developers
Relationship Between JDK, JRE and JVM
+---------------------------------------------+
| JDK |
| |
| +-------------------------------------+ |
| | JRE | |
| | | |
| | +-----------------------------+ | |
| | | JVM | | |
| | +-----------------------------+ | |
| | | |
| | Java Libraries & Runtime | |
| +-------------------------------------+ |
| |
| Compiler • Debugger • JAR • Javadoc |
+---------------------------------------------+
Difference Between JDK, JRE and JVM
Feature JVM JRE JDK
Java Virtual Java Runtime
Full Form Java Development Kit
Machine Environment
Executes Develops & Runs Java
Purpose Runs Java Programs
Bytecode Programs
Contains JVM ❌ ✅ ✅
Contains Libraries ❌ ✅ ✅
Contains Compiler
❌ ❌ ✅
(javac)
Used By Runtime System End User Developer
Platform Dependent ✅ ✅ ✅
JDK Important Tools
Tool Purpose
javac Compiles .java into .class
java Executes Java program
Tool Purpose
jar Creates JAR files
javadoc Generates documentation
jdb Debugging tool
jshell Interactive Java Shell
Java Program Execution Flow
[Link]
│
▼
javac [Link]
│
▼
[Link] (Bytecode)
│
▼
Class Loader
│
▼
Bytecode Verifier
│
▼
JVM Runtime
│
▼
Interpreter
│
▼
JIT Compiler (Frequently Used Code)
│
▼
Machine Code
│
▼
Output
Step-by-Step Execution
Step 1: Write the Program
class Hello {
public static void main(String[] args) {
[Link]("Hello Java");
}
}
⬇
Step 2: Compile
javac [Link]
Output:
[Link]
The compiler converts source code into Bytecode.
⬇
Step 3: Execute
java Hello
The JVM loads the bytecode, verifies it, executes it, and displays the output.
Why is Java Platform Independent?
Because Java source code is converted into Bytecode, not machine code.
The same .class file can run on:
Windows
Linux
macOS
provided each system has a compatible JVM.
Key Point: Bytecode is platform-independent, while the JVM implementation is platform-
specific.
Interview Insight
Q1. Can we run a Java program without JDK?
Answer: Yes, if the program is already compiled. The JRE (which includes the JVM) is
sufficient to execute a .class file.
Q2. Can we compile Java code using JRE?
Answer: No. Compilation requires the javac compiler, which is part of the JDK, not the JRE.
Q3. Which component makes Java platform-independent?
Answer: The JVM, by executing platform-independent bytecode on different operating
systems.
Q4. Why is JVM platform-dependent?
Answer: Every operating system requires its own JVM implementation to translate bytecode
into native machine instructions.
Q5. Is Bytecode machine code?
Answer: No. Bytecode is an intermediate, platform-independent instruction set executed by
the JVM.
Common Mistakes
❌ JDK = JVM
✔ Wrong
JDK contains the JRE, and the JRE contains the JVM.
❌ JVM compiles Java code
✔ Wrong
The javac compiler in the JDK compiles .java files into bytecode. The JVM only executes that
bytecode.
❌ JRE contains the compiler
✔ Wrong
Only the JDK includes development tools like javac.
Key Takeaways
JDK is used to develop Java applications.
JRE is used to run Java applications.
JVM executes Bytecode.
javac converts .java → .class.
java runs the .class file.
JDK ⊃ JRE ⊃ JVM (JDK contains JRE, and JRE contains JVM).
Bytecode is platform-independent, while the JVM is platform-dependent.