Java Quick Revision Notes - Part 1, 2, 3 & 4
■ 1. What is Java?
■ Concept
- Java is a high-level, class-based, object-oriented programming language.
- Developed by James Gosling at Sun Microsystems in 1995.
- Known for platform independence → "Write Once, Run Anywhere (WORA)".
- Runs using JVM (Java Virtual Machine) which executes bytecode.
■ Important Rules / Exceptions
1. Java is case-sensitive (main ≠ Main).
2. The file name must match the public class name.
3. Only one public class allowed per .java file.
4. main method signature must be:
public static void main(String[] args)
- args can have any name, but String[] type is mandatory.
5. Without main, Java program won’t run (except JShell or static block before Java 7).
■ Interview Questions
- Why is Java called platform independent?
- Difference between JDK, JRE, JVM?
- Can we run a Java program without main() method?
- Why is main() method public static void?
- Is Java 100% Object-Oriented?
■■ Example
class HelloJava {
public static void main(String[] args) {
System.out.println("Hello Java!");
}
}
■ Tips to Remember
- Java = OOP + Platform Independent + Secure + Robust.
- Keywords like goto & const are reserved in Java but not used.
- Always think of Java as a language + platform (JVM).
■ 2. History of Java
■ Concept
- 1991 → Project started by James Gosling & team at Sun Microsystems (called Oak).
- 1995 → Officially released as Java (since Oak was trademarked).
- Designed for embedded systems, interactive TV, later adapted for internet applications.
- 1996 → First JDK (Java Development Kit 1.0).
- 2009 → Oracle acquired Sun Microsystems → Java under Oracle.
- Today → widely used in Enterprise, Android, Microservices, Big Data, Cloud.
■ Important Rules / Exceptions
- Java versioning follows major releases (Java SE 8, 11, 17, 21 are LTS).
- Backward compatibility → Old Java code usually works in newer versions.
- Applets & Java Web Start deprecated & removed in Java 11+.
■ Interview Questions
- Who is the father of Java?
- Why was Java initially named Oak?
- What was Java’s original purpose?
- Which company owns Java now?
- Which Java versions are LTS?
■■ Example (Timeline)
1995 → Java 1.0
2004 → Java 5 (Generics, Annotations)
2011 → Java 7 (try-with-resources, switch on String)
2014 → Java 8 (Lambdas, Streams, Default Methods)
2017 → Java 9 (Modules)
2018 → Java 11 (LTS, Removed Applets, JavaFX out)
2021 → Java 17 (LTS, Sealed classes, Pattern Matching)
2023 → Java 21 (LTS, Virtual Threads)
■ Tips to Remember
- Java’s slogan: "Write Once, Run Anywhere."
- Always know Java 8, 11, 17, 21 → most used in industry.
- Interviewers often ask what changed in latest LTS version.
■ 3. Features of Java
■ Concept
Java provides a rich set of features that made it popular and widely used.
Main Features:
1. Simple – Syntax similar to C/C++, no pointers, no operator overloading.
2. Object-Oriented – Everything is in the form of classes & objects.
3. Platform-Independent – Code compiles to bytecode, runs on any JVM.
4. Secure – No direct memory access (like pointers), runs in JVM sandbox.
5. Robust – Strong memory management + exception handling.
6. Multithreaded – Supports multiple threads of execution.
7. High Performance – Uses JIT (Just-In-Time) compiler.
8. Distributed – Supports networking & RMI.
9. Portable – Same bytecode runs on different machines.
10. Dynamic – Supports runtime polymorphism, reflection, and dynamic class loading.
■ Important Rules / Exceptions
- Java does not support multiple inheritance with classes, but supports it with interfaces.
- final keyword prevents inheritance, overriding, or reassignment.
- Garbage Collection is automatic, but System.gc() is only a request, not a guarantee.
- Pointers & operator overloading are intentionally removed for simplicity & security.
■ Interview Questions
- Why is Java platform-independent?
- Difference between robustness and security in Java?
- How does Java achieve multithreading?
- Why doesn’t Java support multiple inheritance with classes?
- How is Java different from C++?
■■ Example
class FeatureDemo {
public static void main(String[] args) {
// Object-Oriented
Person p = new Person("Sahil");
p.display();
// Robust (exception handling)
try {
int x = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Exception handled: " + e);
}
// Multithreaded
Thread t = new Thread(() -> System.out.println("Thread running..."));
t.start();
}
}
class Person {
String name;
Person(String name) { this.name = name; }
void display() { System.out.println("Hello " + name); }
}
■ Tips to Remember
- Always mention WORA (Write Once, Run Anywhere).
- OOPS principles (Encapsulation, Inheritance, Polymorphism, Abstraction) are hot interview topics.
- Java is not 100% OOP (because of primitives like int, char).
- Security & Robustness are always tested in interviews with tricky exception handling questions.
■ 4. JDK, JRE, JVM
■ Concept
1. JVM (Java Virtual Machine)
- Executes Java bytecode line by line.
- Provides platform independence.
- Handles memory management & garbage collection.
2. JRE (Java Runtime Environment)
- Contains JVM + Libraries + Runtime Classes.
- Used to run Java programs.
- Does not have development tools (compiler, debugger).
3. JDK (Java Development Kit)
- Contains JRE + Development Tools (javac, javadoc, debugger).
- Needed for both development & execution.
- Multiple versions available (Standard Edition, Enterprise Edition, etc.).
■ Important Rules / Exceptions
- JDK = JRE + Development Tools.
- JRE = JVM + Libraries.
- JVM is platform-dependent (different implementation per OS), but bytecode is
platform-independent.
- Java 11 onwards: JRE is no longer provided separately, only JDK includes everything.
- HotSpot JVM is the most widely used implementation.
■ Interview Questions
- Difference between JDK, JRE, and JVM?
- Is JVM platform-independent?
- Why is Java platform-independent but JVM is not?
- What is the role of JIT compiler in JVM?
- Can we run Java without JDK installed?
■■ Example (Flow of Compilation & Execution)
Source Code (.java)
↓ [javac compiler]
Bytecode (.class)
↓ [JVM → Class Loader → JIT Compiler → Execution Engine]
Machine Code (OS specific)
class Demo {
public static void main(String[] args) {
System.out.println("Hello from JVM!");
}
}
Compile: javac Demo.java
Run: java Demo
■ Tips to Remember
- Compilation vs Execution: javac compiles → JVM executes.
- Java 11+: only JDK is shipped, no separate JRE.
- JIT Compiler improves performance by compiling bytecode to native machine code at runtime.
- Formula:
- JDK = JRE + Development Tools
- JRE = JVM + Libraries