Skip to content

Latest commit

 

History

History
445 lines (283 loc) · 11.1 KB

File metadata and controls

445 lines (283 loc) · 11.1 KB

History and Features of Java

1. History of Java

Origin and Creation

Java was developed by James Gosling and his team (known as the "Green Team") at Sun Microsystems in 1991.

  • Originally named "Oak" (after an oak tree outside Gosling's office)

  • Later renamed to "Java" (inspired by Java coffee)

  • Initial goal: Create a language for embedded systems and interactive television

  • Official release: May 23, 1995 — Java 1.0

Timeline:
1991 → Project Green started
1995 → Java 1.0 released
2006 → Sun Microsystems open-sourced Java
2010 → Oracle acquired Sun Microsystems

Why Was Java Created?

The Green Team wanted to solve key problems in software development:

Problem Java's Solution
Platform dependency (C++) Platform-independent bytecode
Memory management Automatic garbage collection
Pointer complexity No explicit pointers
Security vulnerabilities Built-in security features
Complex syntax Simple, clean OOP-based syntax

Java Evolution — Major Versions

Version Year Key Features
Java 1.0 1996 Initial release
Java 1.2 1998 Collections Framework, JIT compiler
Java 5 2004 Generics, Annotations, Enums, Autoboxing
Java 8 2014 Lambda Expressions, Stream API, Functional Programming
Java 9 2017 Module System (Project Jigsaw), JShell
Java 11 2018 LTS, HTTP Client API, var for lambda parameters
Java 17 2021 LTS, Sealed Classes, Pattern Matching
Java 21 2023 LTS, Virtual Threads, Record Patterns, Pattern Matching

LTS = Long-Term Support (supported for 8+ years)


2. Features of Java

Java is known as a robust, secure, and platform-independent programming language.


1. Simple and Easy to Learn

Java has:

  • Clean, readable syntax inspired by C/C++

  • Automatic memory management (Garbage Collection)

  • No pointers, no operator overloading

  • Rich standard library

// Simple Hello World
public class Demo {
    public static void main(String[] args) {
        System.out.println("Hello, Java!");
    }
}

2. Platform Independent (Write Once, Run Anywhere)

Java code is compiled to bytecode, not machine code.

Source Code (.java) → Compiler (javac) → Bytecode (.class) → JVM (any platform)
  • Bytecode is platform-independent

  • JVM is platform-dependent (Windows, Linux, macOS have different JVMs)

  • Same .class file runs on any system with JVM

// Example
public class Test {
    public static void main(String[] args) {
        System.out.println("Runs on any OS!");
    }
}

✅ Same bytecode runs on Windows, Linux, macOS.


3. Object-Oriented Programming (OOP)

Java is purely object-oriented (except primitives).

OOP Pillars:

Concept Description
Encapsulation Bundling data and methods together
Inheritance Reusing code from parent classes
Polymorphism Same method, different behavior
Abstraction Hiding implementation details
class Animal {
    void sound() {
        System.out.println("Animal makes sound");
    }
}

class Dog extends Animal {
    void sound() {
        System.out.println("Dog barks");
    }
}

4. Robust and Secure

Robust:

  • Strong type checking at compile time

  • Exception handling (try-catch)

  • Automatic garbage collection

  • No pointer arithmetic

Secure:

  • Bytecode verifier checks for illegal code

  • No explicit pointers → prevents memory manipulation

  • Security Manager controls access to resources

  • ClassLoader provides namespace isolation


5. Multithreading

Java has built-in support for multithreading.

  • Execute multiple threads concurrently

  • Efficient CPU utilization

  • Built-in Thread class and Runnable interface

class MyThread extends Thread {
    public void run() {
        System.out.println("Thread is running");
    }
}

public class Demo {
    public static void main(String[] args) {
        MyThread t = new MyThread();
        t.start();  // starts a new thread
    }
}

6. Automatic Memory Management (Garbage Collection)

Java automatically manages memory using Garbage Collection (GC).

  • Developers don't need to manually free memory

  • GC removes unused objects from heap memory

  • Prevents memory leaks

// Object created on heap
Student s = new Student();

// When no reference exists, GC removes it automatically
s = null;  // eligible for garbage collection

7. High Performance

Java uses Just-In-Time (JIT) Compiler:

  • Converts frequently executed bytecode into native machine code at runtime

  • Improves execution speed significantly

Bytecode → JIT Compiler → Native Machine Code (faster execution)

8. Distributed Computing

Java supports distributed applications:

  • RMI (Remote Method Invocation)

  • EJB (Enterprise JavaBeans)

  • Web Services

  • Networking APIs (Socket, URL, HttpClient)


9. Dynamic and Extensible

  • Java can load classes dynamically at runtime

  • Reflection API allows inspection of classes/methods at runtime

Class<?> c = Class.forName("java.lang.String");
System.out.println(c.getName());  // java.lang.String

10. Rich API and Libraries

Java provides extensive libraries:

Library Purpose
java.lang Core classes (String, Math)
java.util Collections, Date/Time
java.io File I/O operations
java.net Networking
java.sql Database connectivity
java.awt/swing GUI development

3. Comparison: Java vs C++ vs Python

Feature Java C++ Python
Platform Independence ✅ Yes (JVM) ❌ No ✅ Yes (interpreter)
Memory Management Automatic (GC) Manual (new/delete) Automatic (GC)
Pointers ❌ No ✅ Yes ❌ No
Multithreading Built-in Library-based Built-in (GIL)
Performance High (JIT) Very High (compiled) Lower (interpreted)
Type System Static Static Dynamic
Syntax Moderate Complex Simple

4. Real-World Applications of Java

Java is used in:

Application Area Examples
Web Applications Spring Boot, JSP, Servlets
Android Development Android apps
Enterprise Systems Banking, E-commerce, ERP systems
Big Data Hadoop, Apache Spark
Cloud Computing AWS, Azure, Google Cloud services
Desktop Applications IntelliJ IDEA, Eclipse IDE
Embedded Systems Smart cards, IoT devices
Scientific Computing MATLAB, simulation tools

5. Java's Design Principles

James Gosling defined 5 design goals for Java:

  1. Simple, Object-Oriented, and Familiar

    • Based on C++ but simpler
  2. Robust and Secure

    • Strong type checking, exception handling
  3. Architecture-Neutral and Portable

    • Bytecode runs on any platform
  4. High Performance

    • JIT compiler optimizations
  5. Interpreted, Threaded, and Dynamic

    • Bytecode interpreted by JVM
    • Built-in multithreading support

6. Java Compilation and Execution Flow

Step 1: Write code
   Demo.java

Step 2: Compile
   javac Demo.java → Demo.class (bytecode)

Step 3: Execute
   java Demo → JVM interprets bytecode

Detailed Flow:

.java → javac (Compiler) → .class (Bytecode)
                                ↓
                    JVM (Class Loader → Bytecode Verifier → Interpreter/JIT)
                                ↓
                        Native Machine Code
                                ↓
                            Execution

7. Interview Questions & Nuggets

Q1: Why is Java called "Platform Independent"?

Java compiles to bytecode, which runs on JVM. JVM is platform-specific, but bytecode is not.

Q2: What does "Write Once, Run Anywhere" mean?

Same .class file (bytecode) runs on any OS that has JVM installed.

Q3: Is Java 100% object-oriented?

No. Primitives (int, char, float, etc.) are not objects.

Q4: Why doesn't Java have pointers?

To prevent:

  • Memory manipulation
  • Security vulnerabilities
  • Errors caused by pointer arithmetic

Q5: What is Bytecode Verifier?

A component of JVM that checks bytecode for:

  • Illegal instructions
  • Type violations
  • Stack overflows

Q6: What is JIT Compiler?

Just-In-Time Compiler converts frequently used bytecode into native machine code for faster execution.

Q7: What are the major Java versions used in production?

Java 8, Java 11, Java 17, Java 21 (all LTS versions)

Q8: Why was Java created?

To solve platform dependency, memory management, and security issues in C/C++.

Q9: What is the difference between JDK, JRE, and JVM?

  • JDK = Development tools + JRE
  • JRE = JVM + Libraries
  • JVM = Executes bytecode

Q10: What are the key features of Java 8?

  • Lambda Expressions
  • Stream API
  • Functional Interfaces
  • Default and Static methods in interfaces
  • Optional class

8. Why Java is Still Popular?

  1. Large Community — Extensive documentation, forums, tutorials

  2. Enterprise Adoption — Used by Google, Amazon, Netflix, LinkedIn

  3. Rich Ecosystem — Spring, Hibernate, Apache libraries

  4. Backward Compatibility — Old code runs on newer versions

  5. Job Market Demand — High demand for Java developers

  6. Android Development — Primary language for Android apps (along with Kotlin)


Key Takeaways

  • Java was created in 1995 by James Gosling at Sun Microsystems

  • Platform-independent due to bytecode and JVM

  • Object-oriented, robust, secure, and multithreaded

  • Uses automatic garbage collection for memory management

  • JIT compiler provides high performance

  • Used in web, mobile, enterprise, big data, and cloud applications

  • LTS versions: Java 8, 11, 17, 21