0% found this document useful (0 votes)
12 views28 pages

Abuzar Assignment 1

The document is an assignment on Object-Oriented Programming (OOP) that covers the Java Development Kit (JDK), its components, and its purpose in Java development. It also outlines the evolution of Java through its major versions, highlighting key features and impacts, as well as comparing Java SE and Java EE. Additionally, it provides a detailed guide on Java syntax, including basic rules, data types, control flow, and method definitions.

Uploaded by

itsareeba234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views28 pages

Abuzar Assignment 1

The document is an assignment on Object-Oriented Programming (OOP) that covers the Java Development Kit (JDK), its components, and its purpose in Java development. It also outlines the evolution of Java through its major versions, highlighting key features and impacts, as well as comparing Java SE and Java EE. Additionally, it provides a detailed guide on Java syntax, including basic rules, data types, control flow, and method definitions.

Uploaded by

itsareeba234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Submitted By: Abuzar Ghaffari

Submitted To: Ahmed Zeeshan


Roll No: BSCS012415085
Subject: OOPs
Assignment 1

1
Question 1:
1. Definition of JDK
The Java Development Kit (JDK) is a software development environment used to
create, compile, debug, and run Java applications. It is a superset of the Java
Runtime Environment (JRE) and includes additional tools necessary for developing
Java programs.
• Developed by: Oracle (previously Sun Microsystems)
• Primary Use: Compiling and building Java applications
• Platform Dependency: JDK is platform-specific (different versions for
Windows, macOS, Linux)

2. Components of JDK
The JDK consists of several key components:
A. Development Tools
1. javac (Java Compiler)
❖ Converts Java source code (.java) into bytecode (.class).
❖ Example: javac HelloWorld.java → Generates HelloWorld.class.
2. java (Java Launcher)
❖ Executes Java applications by running the JVM.
❖ Example: java HelloWorld
3. javadoc (Documentation Generator)
❖ Generates API documentation in HTML format from Java source
code comments.
❖ Example: javadoc HelloWorld.java
4. jdb (Java Debugger)
❖ Helps in debugging Java programs.
❖ Example: jdb HelloWorld
5. jar (Java Archive Tool)
❖ Packages compiled .class files into a JAR (Java Archive) for
distribution.
❖ Example: jar cvf MyApp.jar HelloWorld.class
6. javap (Class File Disassembler)
❖ Disassembles .class files to view bytecode.
❖ Example: javap HelloWorld
2
B. Java Runtime Environment (JRE)
• Contains the JVM and core libraries required to run Java applications.
• Included in JDK because compiled programs need a runtime environment.
C. Java Class Libraries (rt.jar, java.*, javax.*)
• Predefined classes and methods for common tasks (e.g., I/O, networking,
collections).
• Examples:
❖ java.lang (basic classes like String, System)
❖ java.util (collections, date/time handling)
❖ java.io (file handling)
D. Header Files (for Native Code Integration)
• Used when combining Java with C/C++ (JNI - Java Native Interface).
E. Additional Tools
• jconsole – Monitors JVM performance.
• jvisualvm – Profiling and troubleshooting tool.
• keytool – Manages security certificates.

3. Purpose of JDK in Java Development


The JDK serves multiple essential roles in Java development:
A. Compilation (javac)
• Converts human-readable .java files into machine-
independent .class (bytecode).
• Without JDK, you cannot compile Java code.
B. Execution (java)
• Runs Java applications using the JVM (which is part of the JRE inside JDK).
C. Debugging & Profiling (jdb, jvisualvm)
• Helps developers find and fix errors in Java programs.
D. Documentation (javadoc)
• Generates API documentation automatically from source code comments.
E. Packaging & Distribution (jar)
• Bundles compiled classes into JAR/WAR files for deployment.
F. Native Integration (JNI)

3
• Allows Java to interact with C/C++ code.

Question 2:
1. Java 1.0 (January 1996) - The Beginning
• Codename: Oak
• Significance: First public release of Java
• Key Features:
➢ Introduced the "Write Once, Run Anywhere" (WORA) concept
➢ Basic language features: classes, objects, inheritance
➢ Primitive GUI support through AWT (Abstract Window Toolkit)
➢ Basic networking support
➢ Limited standard library compared to modern versions
Impact: Established Java as a promising new language for web development
(applets) and general-purpose programming, though very limited by today's
standards.
2. Java 1.2 (December 1998) - The Collections Revolution
• Codename: Playground
• Significance: Major overhaul of Java's capabilities
• Key Features:
Collections Framework (java.util package):
Introduced List, Set, Map interfaces
Implementations like ArrayList, HashSet, HashMap
Swing (new GUI framework):
Replaced AWT with more powerful components
Pluggable look-and-feel
Just-In-Time (JIT) Compiler:
Significant performance improvements
Java IDL (CORBA support)
Java 2D API for advanced graphics
Impact: Transformed Java from a simple language to a robust platform for
application development. The Collections Framework became fundamental to
nearly all Java programs.
3. Java 5 (September 2004) - The Language Matures

4
• Codename: Tiger
• Significance: Most significant language update since 1.0
• Key Features:
Generics:
Type safety for collections: List<String>
Eliminated many ClassCastException scenarios
Enhanced for-loop:
Simplified iteration: for (String s : list)
Autoboxing/Unboxing:
Automatic conversion between primitives and wrappers
Enums:
Type-safe enumerations with methods
Varargs:
Variable arguments: void method(String... args)
Annotations:
Metadata support (@Override, @Deprecated)
Concurrency utilities (java.util.concurrent):
Thread pools, concurrent collections
Impact: These features made Java code more expressive, safer, and easier
to maintain. Generics in particular changed how Java developers worked with
collections.
4. Java 8 (March 2014) - The Functional Shift
• Significance: Biggest update since Java 5
• Key Features:
Lambda Expressions:
Enabled functional programming: (a, b) -> a + b
Stream API:
Functional-style operations on collections:
Optional:
Null-safe container: Optional<String>
New Date/Time API (java.time):

5
Immutable classes: LocalDate, ZonedDateTime
Fixed issues with old Date/Calendar
Default Methods in Interfaces:
Allowed backward-compatible API evolution
Nashorn JavaScript Engine:
Embedded JavaScript runtime
Impact: Revolutionized how Java code is written, enabling more concise and
expressive programming styles. The Stream API changed how data
processing is done in Java.
5. Java 11 (September 2018) - LTS Modernization
• Significance: Current long-term support version
• Key Features:
HTTP Client (Standard):
Modern replacement for HttpURLConnection
Supports HTTP/2 and WebSockets
Local-Variable Syntax for Lambda Parameters:
Allowed var in lambdas: (var x, var y) -> x + y
New String Methods:
isBlank(), lines(), repeat(n), strip()
Launch Single-File Programs:
Run .java files directly without compilation
Flight Recorder:
Production-time profiling tool
ZGC (Experimental):
Scalable low-latency garbage collector
Impact: Solidified Java's position for modern cloud-native development while
improving developer productivity.
6. Java 17 (September 2021) - The Modern Java
• Significance: Current LTS with long-term support
• Key Features:
Sealed Classes:

6
Restricted inheritance: permits clause
Pattern Matching for instanceof:
Simplified type checks:
Text Blocks:
Multiline strings without escape sequences:
Records:
Immutable data carriers:
New macOS Rendering Pipeline
Strong encapsulation of JDK internals
Impact: Made Java more concise and safer while preparing for future pattern
matching enhancements.
7. Java 21 (September 2023) - The Concurrency Revolution
• Significance: Latest LTS release
• Key Features:
Virtual Threads (Project Loom):
Lightweight threads for high-throughput concurrency
Dramatically simplifies concurrent programming
Record Patterns:
Deconstruct records in pattern matching:
Sequenced Collections:
New interfaces for ordered collections
String Templates (Preview):
Safer string interpolation
Generational ZGC:
Improved garbage collection performance
Impact: Virtual threads represent the biggest change to Java's concurrency
model in decades, potentially eliminating the need for reactive programming in
many cases.
Evolutionary Trends:
1. Language Expressiveness (Generics, Lambdas, Records)
2. Performance (JIT, New GCs, Valhalla upcoming)

7
3. Developer Productivity (var, Text Blocks)
4. Modern Architectures (Modules, Cloud-Native)
5. Concurrency (Virtual Threads)
Each major version has built upon previous ones while introducing paradigm-
shifting features that keep Java relevant in modern software development.
The LTS releases (8, 11, 17, 21) represent particularly important milestones
that enterprises standardize on.

Question 3:
1. Java SE (Standard Edition)
Definition
Java SE (Standard Edition) is the core Java platform that provides the
fundamental infrastructure and APIs needed to develop general-purpose Java
applications.
Key Components
• Java Language Basics (syntax, OOP features)
• Core Libraries (java.lang, java.util, java.io)
• JVM (Java Virtual Machine)
• Development Tools (javac, java, javadoc)
• Basic APIs (Collections, I/O, Networking, Concurrency)
Primary Uses

✔ Desktop Applications (Swing, JavaFX)


✔ Command-line Tools
✔ Embedded Systems
✔ Android Development (via subset of Java SE APIs)
✔ Educational Purposes (learning Java fundamentals)
Example Technologies in Java SE
• Swing/JavaFX (GUI development)
• JDBC (Basic database connectivity)
• Java NIO (Non-blocking I/O)
• Java Streams API (Data processing)

2. Java EE (Enterprise Edition)


Definition

8
Java EE (Enterprise Edition), now called Jakarta EE, is an extended
platform built on top of Java SE that provides APIs and runtime environments
for developing large-scale, distributed enterprise applications.
Key Components
• Web Technologies (Servlets, JSP, JSF)
• Enterprise Services (EJB, JTA, JMS)
• Persistence (JPA)
• Security (JAAS, JASPIC)
• Web Services (JAX-RS, JAX-WS)
Primary Applications

✔ Web Applications (Dynamic websites)


✔ Enterprise Software (ERP, CRM systems)
✔ Microservices (With modern Jakarta EE)
✔ Distributed Systems (Banking, e-commerce)
✔ Cloud-Native Applications
Example Technologies in Java EE
• Servlets & JSP (Web components)
• Enterprise JavaBeans (EJB) (Business logic)
• Java Persistence API (JPA) (Database ORM)
• Java Message Service (JMS) (Messaging)
• RESTful Web Services (JAX-RS) (API development)

3. Java SE vs. Java EE: Detailed Comparison

Feature Java SE Java EE

General-purpose Enterprise-scale
Purpose
programming applications

Beginners, Enterprise
Target Users desktop developers, web
developers engineers

Standalone apps, Application servers


Deployment
JAR files (Tomcat, WildFly)

9
Feature Java SE Java EE

Limited (Basic Full stack (Servlets,


Web Support
HTTP) JSP, JSF)

Database JPA (Advanced


JDBC (Basic)
Access ORM)

Transaction
Manual Automated (JTA)
Mgmt

Advanced (JASPIC,
Security Basic (JAAS)
Security Annotations)

Managed threads
Concurrency Thread API
(EJB)

JMS (Queue/Topic
Messaging Not included
support)

Dependency
Manual/JAR files Built-in (CDI)
Mgmt

Online banking
Example Use Calculator app,
system, E-commerce
Case File utilities
platform

4. Key Differences Explained


(1) Architecture
• Java SE: Single-tier or client-server architecture
• Java EE: Multi-tier architecture (Presentation, Business, Data layers)
(2) Scalability
• Java SE: Limited scalability for small apps
• Java EE: Designed for horizontal scaling (clustering, load balancing)
(3) Transaction Management
• Java SE: Manual commit/rollback
• Java EE: Declarative transactions via @Transactional

10
(4) Security
• Java SE: Basic authentication
• Java EE: Role-based access control (RBAC), SSL integration
(5) Development Complexity
• Java SE: Simpler, fewer dependencies
• Java EE: More boilerplate but provides enterprise-grade reliability
5. When to Use Which?
Choose Java SE When:
• Building desktop applications
• Developing simple utilities
• Learning core Java concepts
• Working on Android apps (though Android uses a modified Java SE)
Choose Java EE (Jakarta EE) When:
• Building web applications
• Developing microservices
• Needing distributed transactions
• Requiring enterprise security
• Working with legacy enterprise systems

6. Evolution to Jakarta EE
• 2017: Oracle donated Java EE to Eclipse Foundation
• 2019: Renamed to Jakarta EE due to trademark issues
• Current: Jakarta EE 10 (2022) supports modern cloud-native development
Note: Modern enterprise development often uses Spring Boot (built on Java
SE) as an alternative to traditional Java EE.

Question 4:
Java Syntax: A Detailed Guide
1. Basic Syntax of Java
Java syntax follows strict rules that define how programs are written and interpreted.
Key elements include:
A. Case Sensitivity

11
• Java is case-sensitive (myVar ≠ myvar ≠ MYVAR)
B. Class Names
• Should start with uppercase (PascalCase)
• Example: MyClass, EmployeeDetails
C. Method Names
• Should start with lowercase (camelCase)
• Example: calculateSalary(), printDetails()
D. File Naming
• File name must match the public class name (e.g., HelloWorld.java for public
class HelloWorld)
E. Main Method
• Entry point of every Java program:
public static void main(String[] args)
2. Simple "Hello, World!" Program
// 1. Define a class (filename must be HelloWorld.java)
public class HelloWorld {
// 2. Main method - program entry point
public static void main(String[] args) {
// 3. Print to console
System.out.println("Hello, World!");
}
}
How to Run:
1. Save as HelloWorld.java
2. Compile: javac HelloWorld.java
3. Run: java HelloWorld
Output:
Hello, World!

3. Java Syntax Rules & Structure


A. Comments

12
// Single-line comment

/*
Multi-line
comment
*/

/**
* Javadoc comment (for documentation)
*/
B. Data Types

Primitive Types Size Example

byte 1 byte byte b = 100

int 4 bytes int i = 1000

double 8 bytes double d = 3.14

boolean 1 bit boolean flag = true

Reference Types: String, Arrays, Objects


C. Variables
java
Copy
int age = 25; // Declaration + initialization
final double PI = 3.14159; // Constant (cannot be changed)
String name = "Alice"; // String object
D. Operators

Type Examples

Arithmetic +, -, *, /, %

13
Type Examples

Comparison ==, !=, >, <

Logical &&, `

Assignment =, +=, -=

E. Control Flow
If-Else
java
Copy
if (age >= 18) {
System.out.println("Adult");
} else {
System.out.println("Minor");
}
For Loop
java
Copy
for (int i = 0; i < 5; i++) {
System.out.println(i);
}
While Loop
java
Copy
int i = 0;
while (i < 5) {
System.out.println(i);
i++;
}
F. Methods
java
14
Copy
// Method definition
public static int add(int a, int b) {
return a + b;
}

// Method call
int sum = add(5, 3); // Returns 8
G. Classes & Objects
java
Copy
// Class definition
public class Dog {
// Field
String breed;

// Method
public void bark() {
System.out.println("Woof!");
}
}

// Object creation
Dog myDog = new Dog();
myDog.breed = "Labrador";
myDog.bark(); // Output: "Woof!"

4. Key Syntax Features


A. Semicolons
• Required at the end of each statement:

15
java
Copy
int x = 5; // Semicolon mandatory
B. Blocks
• Defined by curly braces {}:
if (condition) {
// Block starts
System.out.println("Inside block");
// Block ends
}
C. Indentation
• Not enforced but highly recommended for readability:
// Good
if (condition) {
doSomething();
}

// Bad (hard to read)


if(condition){
doSomething();}
D. Naming Conventions

Element Convention Example

Class PascalCase EmployeeDetails

Method/Variable camelCase calculateSalary

Constant UPPER_SNAKE_CASE MAX_SPEED

5. Common Syntax Errors


1. Missing Semicolon
java
16
Copy
int x = 5 // Error: missing ';'
2. Mismatched Braces
java
Copy
if (condition) {
System.out.println("Hello");
// Missing closing brace
3. Case Sensitivity Errors
java
Copy
String name = "Alice";
System.out.println(Name); // Error: 'Name' ≠ 'name'
4. Incorrect Main Method
java
Copy
// Wrong
public static void Main(String[] args) {} // 'Main' ≠ 'main'

6. Advanced Syntax (Java 8+)


Lambda Expressions
java
Copy
// Before Java 8
Runnable r = new Runnable() {
public void run() {
System.out.println("Running");
}
};

17
// Java 8+
Runnable r = () -> System.out.println("Running");
Try-With-Resources
java
Copy
try (FileReader fr = new FileReader("file.txt")) {
// Auto-closes resource
} catch (IOException e) {
e.printStackTrace();
}

Question 5:
Java History & Key Companies: Sun Microsystems and Oracle
1. The Birth and Evolution of Java
Origins (1991-1995)
• 1991: James Gosling and his team at Sun Microsystems (the "Green Team")
began developing a language for interactive television and embedded
devices.
• Original Name: "Oak" (named after a tree outside Gosling's office)
• 1994: Shifted focus to web applications as the internet began booming
• 1995: Officially renamed to "Java" (inspired by Java coffee) and released
publicly
Key Milestones
• 1996: Java 1.0 released with the "Write Once, Run Anywhere" promise
• 1998: Java 1.2 rebranded as "Java 2" with three editions (J2SE, J2EE, J2ME)
• 2004: Java 5 introduced generics, autoboxing, enums, and varargs
• 2006: Sun open-sourced Java under GPL license (OpenJDK)
• 2010: Oracle acquired Sun Microsystems
• 2014: Java 8 brought lambdas and streams
• 2017: Java 9 introduced the module system
• 2021: Java 17 (LTS) with sealed classes and pattern matching
• 2023: Java 21 introduced virtual threads (Project Loom)

18
2. Sun Microsystems' Role (1995-2010)
Contributions
• Developed the original Java language and JVM
• Established Java as a web technology through applets
• Created the Java Community Process (JCP) for open governance
• Introduced key enterprise technologies (J2EE)
• Open-sourced Java as OpenJDK (2006)
Challenges
• Legal battles with Microsoft over Java implementation
• Declining hardware business leading to financial troubles
• Eventually acquired by Oracle in 2010 for $7.4 billion
3. Oracle's Role (2010-Present)
Major Changes
• Shifted to a 6-month release cycle (starting with Java 9)
• Introduced paid commercial features in Oracle JDK
• Donated Java EE to Eclipse Foundation (now Jakarta EE)
• Focused on enterprise and cloud capabilities
• Won then lost a major copyright case against Google over Android
Recent Developments
• Continued innovation with projects like Loom (virtual threads)
• Maintained Java's position as a top enterprise language
• Balanced open-source (OpenJDK) with commercial offerings
4. Java Today
• Still one of the world's most popular programming languages
• Widely used in enterprise systems, Android apps, and cloud computing
• Maintains strong backward compatibility while innovating
• Governed through a mix of Oracle leadership and community input
Oracle's stewardship has kept Java relevant in the modern computing landscape
while preserving its core strengths of portability, reliability, and performance.
The History of Java and Its Corporate Stewards
1. The Birth and Evolution of Java

19
Origins (1991-1995)
Java was conceived in 1991 by James Gosling and his team at Sun Microsystems
(known as the "Green Team"). Originally named Oak after a tree outside Gosling's
office, the language was designed for interactive television and embedded devices.
When this market failed to materialize, the team pivoted to web applications just as
the internet was taking off.
The language was renamed Java (inspired by Java coffee) and publicly released in
1995 with several revolutionary features:
• Platform independence through the Java Virtual Machine (JVM)
• Built-in security features
• Object-oriented design
• The "Write Once, Run Anywhere" (WORA) principle
Key Historical Milestones
• 1996: Java 1.0 released with core features
• 1998: Java 1.2 rebranded as "Java 2" with three editions (J2SE, J2EE, J2ME)
• 2004: Java 5 introduced generics, autoboxing, and annotations
• 2006: Sun open-sourced Java as OpenJDK
• 2010: Oracle acquired Sun Microsystems
• 2014: Java 8 added lambdas and streams
• 2017: Java 9 introduced the module system
• 2021: Java 17 became the current long-term support version
• 2023: Java 21 introduced virtual threads
2. Sun Microsystems: Java's First Home (1995-2010)
Major Contributions
1. Technology Development
o Created the original Java language specification
o Developed the Java Virtual Machine (JVM)
o Built foundational libraries and tools
2. Platform Expansion
o Established Java editions for different use cases:
▪ J2SE (Standard Edition)
▪ J2EE (Enterprise Edition)

20
▪ J2ME (Micro Edition)
o Pioneered Java applets for web interactivity
3. Community Building
o Created the Java Community Process (JCP) for collaborative
development
o Fostered a large ecosystem of developers and companies
o Open-sourced Java as OpenJDK in 2006
Challenges Faced
• Legal battles with Microsoft over Java implementation
• Difficulty monetizing Java technology
• Declining hardware business leading to financial troubles
• Ultimately acquired by Oracle in 2010
3. Oracle's Stewardship (2010-Present)
Strategic Changes
1. Business Model Shifts
o Introduced commercial licensing for Oracle JDK
o Created subscription models for enterprise support
o Maintained free OpenJDK for community use
2. Technical Evolution
o Accelerated release cycle to every 6 months
o Established Long-Term Support (LTS) versions
o Modernized Java with features like:
▪ Lambdas and streams (Java 8)
▪ Modules (Java 9)
▪ Virtual threads (Java 21)
3. Ecosystem Management
o Transferred Java EE to Eclipse Foundation (now Jakarta EE)
o Continued supporting the Java Community Process
o Invested in performance improvements and new projects
Controversies and Challenges
• High-profile lawsuit against Google over Android's Java use

21
• Tension between commercial and open-source interests
• Competition from alternative JVM languages (Kotlin, Scala)
• Need to balance innovation with backward compatibility
4. Java's Current Position (2024)
Today, Java remains:
• The #1 language for enterprise backend systems
• A key platform for Android development (via Kotlin/JVM)
• Widely used in big data (Hadoop, Spark) and cloud computing
• Supported by a massive global community
• Continuously evolving with projects like:
o Loom (virtual threads)
o Valhalla (value types)
o Panama (native interop)
Both Sun Microsystems and Oracle have played crucial roles in Java's success -
Sun as the innovative creator and Oracle as the pragmatic sustainer that maintained
Java's relevance in the modern computing landscape.

Question 6:
1. Definitions and Key Differences

Component Full Form Purpose Contains Needed By

Executes Bytecode
Java Virtual To run Java
JVM Java interpreter, JIT
Machine programs
bytecode compiler, GC

JVM + Core
Provides End-users
Java Runtime Libraries
JRE runtime running
Environment (rt.jar,
environment Java apps
java.lang, etc.)

JRE +
Java For
Development Java
JDK Development developing
Tools (javac, developers
Kit Java apps
javadoc, etc.)

2. Detailed Explanation of Each Component

22
A. JVM (Java Virtual Machine)
• Function:
o Loads .class files (bytecode)
o Verifies bytecode for security
o Executes code using:
▪ Interpreter: Reads bytecode line-by-line
▪ JIT Compiler: Compiles frequent code to native machine code
o Manages memory (garbage collection)
• Key Points:
o Platform-dependent (different JVMs for Windows/Linux/macOS)
o Enables Java's "Write Once, Run Anywhere"
o Does not include compilers or development tools
B. JRE (Java Runtime Environment)
• Components:
o JVM (for execution)
o Core Libraries (e.g., java.lang, java.util, java.io)
o Supporting files (property files, fonts)
• Purpose:
o Provides minimum environment to run Java applications
o Used by end-users (no development capability)
C. JDK (Java Development Kit)
• Components:
o JRE (to run programs)
o Development Tools:
▪ javac (compiler)
▪ java (launcher)
▪ javadoc (documentation generator)
▪ jdb (debugger)
▪ jar (packaging tool)
o Additional libraries for development

23
• Purpose:
o Used by developers to write, compile, debug, and package Java
apps

3. How These Components Work Together


Java Program Execution Flow:
1. Developer writes code (HelloWorld.java)
→ Uses JDK (which includes javac)
2. Compilation (javac HelloWorld.java)
→ JDK's javac converts .java to .class (bytecode)
3. Execution (java HelloWorld)
→ JRE loads the .class file
→ JVM interprets/compiles bytecode to machine code
→ Program runs

4. Key Comparisons

Feature JVM JRE JDK

Contains Development Yes (javac, jar,


No No
Tools etc.)

Can Compile Code No No Yes

Can Run Code Yes Yes


Yes

Includes Core Libraries No Yes


Yes

Yes
Memory Management Yes
(GC) Yes

5. Practical Scenarios
• End User:
o Only needs JRE to run Java apps (e.g., Minecraft)
o Downloads: JRE installer

24
• Developer:
o Needs full JDK to write and compile code
o Downloads: JDK (includes JRE)
• System Administrator:
o May need JDK for troubleshooting
o Typically installs JRE on production servers

6. Version Compatibility
• JDK version ≥ JRE version ≥ JVM version
• Example:
JDK 21 → Includes JRE 21 → Uses JVM 21
• Mixing versions may cause errors
7. Evolution in Modern Java
• Since Java 9:
o Modularization (JDK split into modules)
o JRE no longer distributed separately (bundled in JDK)
o jlink tool creates custom runtime images

Question 7:
Strengths and Limitations of Java
1. Strengths of Java
A. Platform Independence (WORA Principle)
• Write Once, Run Anywhere (WORA): Java code compiles to bytecode that
runs on any device with a JVM.
• JVM Abstraction: No need to recompile for different operating systems.
• Example: A .class file compiled on Windows runs unchanged on
Linux/macOS.
B. Robust and Secure
• Memory Management: Automatic garbage collection prevents memory leaks.
• Exception Handling: Structured error handling with try-catch-finally.
• Security Features:
o Bytecode verification

25
o Sandboxing for applets
o No pointer arithmetic (prevents buffer overflows)
C. Object-Oriented Programming (OOP)
• Encapsulation, Inheritance, Polymorphism: Clean code organization.
• Modularity: Classes and packages promote reusable code.
• Example:
java
Copy
public class Animal { void sound() {} }
public class Dog extends Animal { void sound() { System.out.println("Bark"); } }
D. Rich Standard Library
• Collections Framework: ArrayList, HashMap, etc.
• I/O & Networking: java.nio, java.net
• Concurrency Utilities: Thread, ExecutorService
• Example:
java
Copy
List<String> names = new ArrayList<>();
names.add("Alice");
E. Multithreading Support
• Built-in Thread Class: Simplified concurrent programming.
• High-Performance: Optimized for multi-core CPUs.
• Example:
java
Copy
new Thread(() -> System.out.println("Running")).start();
F. Backward Compatibility
• Stable APIs: Code written 20 years ago often still runs.
• Deprecation Policy: Features are marked deprecated before removal.
G. Strong Community & Ecosystem

26
• 3rd-Party Libraries: Spring, Hibernate, Apache Commons.
• Tooling: Maven, Gradle, IntelliJ IDEA.
• Community Support: Stack Overflow, GitHub, Oracle forums.

2. Limitations of Java
A. Performance Overhead
• JVM Startup Time: Slower than native languages (C/C++).
• Memory Usage: Higher due to JVM and object overhead.
• Just-In-Time (JIT) Lag: Warm-up time for optimization.
B. Verbosity
• Boilerplate Code: Getters/setters, try-catch blocks.
• Example:
java
Copy
public class Person {
private String name;
public String getName() { return name; } // Verbose
public void setName(String name) { this.name = name; }
}
C. Limited Low-Level Control
• No Pointer Arithmetic: Restricts system programming.
• No Unsigned Types: byte, short, int, long are always signed.
D. Memory Consumption
• Heap Usage: Objects consume more memory than structs in C.
• No Value Types (Pre-Java 16): Primitive wrappers (e.g., Integer) add
overhead.
E. Slower Evolution
• Backward Compatibility: Limits radical changes.
• Slow Adoption of Modern Features: Took years to add lambdas (Java 8,
2014).
F. GUI Weaknesses

27
• AWT/Swing: Outdated compared to modern frameworks.
• JavaFX: Less adoption than web/Android alternatives.
G. Licensing & Commercialization (Oracle JDK)
• Oracle’s Licensing Model: Paid support for LTS versions.
• OpenJDK Fragmentation: Multiple vendors (Amazon, Azul, etc.).
The End

28

You might also like