OOPs 86
OOPs 86
1
Table of Contents
1. Java Development Kit (JDK)............................................................................................... 3
2. Java Versions ................................................................................................................... 4
3. Java Standard Editions (Java SE & Java EE)........................................................................ 7
4. Java Syntax ..................................................................................................................... 10
5. Java History & Company ................................................................................................. 12
6. JVM, JRE, and JDK ........................................................................................................... 15
7. Strength & Limitations of JAVA........................................................................................ 17
2
Assignment #1: Java Development & Versions
1. Java Development Kit (JDK)
The Java Development Kit (JDK) is a software development environment provided by
Oracle (and other vendors) for building applications using the Java programming
language. It is a core component for developing Java programs and includes
everything needed to compile, debug, and run Java applications.
Components of JDK:
The JDK consists of the following main components:
1. Java Compiler (javac)
Translates Java source code (.java files) into bytecode (.class files) that the Java Virtual
Machine (JVM) can execute.
2. Java Runtime Environment (JRE)
Includes the JVM, core libraries, and other components necessary to run Java
applications.
3. Java Virtual Machine (JVM)
Executes Java bytecode and provides platform independence.
4. Java API Libraries
Pre-built classes and interfaces for performing common programming tasks (e.g., data
structures, file handling, networking, etc.).
5. Development Tools
Includes tools like:
▪ javap (class file disassembler),
▪ javadoc (for generating documentation),
▪ jar (for packaging Java files into a .jar archive),
▪ jshell (interactive Java shell for testing code snippets).
6. Debugger (jdb)
Helps in debugging Java applications.
3
• Application Testing and Debugging: Provides tools to test and debug Java
programs effectively.
• Running Java Programs: Through the JRE, it enables running and testing Java
applications.
• Documentation Generation: Allows automatic generation of API
documentation using javadoc.
• Packaging and Deployment: Facilitates packaging of applications using jar and
other tools.
…………………………………
2. Java Versions
ava, since its launch in 1996, has gone through multiple significant updates. Each
version added new features, enhanced performance, and improved developer
productivity. Below is a breakdown of the major Java versions and their most important
additions.
4
Java 1.3 focused on performance and scalability. It included the HotSpot JVM for better
runtime performance. New APIs for audio (Java Sound) were added, and Remote
Method Invocation (RMI) was enhanced to support distributed applications better.
5
asynchronous file channels. Java 7 also enhanced exception handling with
multi-catch and more precise rethrowing.
6
➢ Pattern matching (simplifying instanceof checks),
➢ Records (a concise way to declare data-carrying classes),
➢ Sealed classes (for restricted inheritance).
7
• Learning and teaching object-oriented programming (OOP) concepts such as
classes, objects, inheritance, and polymorphism.
• Developing core algorithms, data structures, and logical programs.
• Basic network programming (sockets, URLs).
• Database applications using JDBC (Java Database Connectivity).
• Graphical User Interfaces (GUI) using libraries such as AWT (Abstract Window
Toolkit) and Swing.
Java SE is also the base platform upon which other editions like Java EE and Java ME
(Micro Edition) are built. Without Java SE, these higher editions cannot function.
8
Java EE applications are typically deployed on application servers such as:
• GlassFish
• WildFly (formerly JBoss)
• Apache TomEE
• IBM WebSphere
• Oracle WebLogic
These servers manage the application lifecycle, security, resource management, and
scalability of enterprise Java applications.
9
• Java EE is used for building multi-tier web applications, enterprise systems,
and large-scale distributed applications.
4. Architecture:
• Java SE applications are typically single-tier, running on a single machine or
user environment.
• Java EE applications are multi-tiered, usually involving:
➢ A client tier (e.g., a web browser or mobile app)
➢ A web tier (e.g., JSP/Servlets)
➢ A business tier (e.g., EJBs, services)
➢ A data tier (e.g., database backend)
5. Development Focus:
• Developers using Java SE focus on the logic and structure of applications,
managing everything manually.
• In Java EE, developers focus on business logic, while the container (application
server) handles security, transactions, resource management, and
scalability.
6. Deployment Environment:
• Java SE applications are deployed on local machines with a JRE.
• Java EE applications are deployed on application servers that manage the
environment and runtime services.
…………………………………
4. Java Syntax
Java syntax refers to the set of rules that define how a Java program should be written
and interpreted by the Java compiler. Java is a strictly-typed, object-oriented, and case-
sensitive programming language, and its syntax is similar to C and C++.
A typical Java program is made up of:
1. Class Declaration
2. Main Method
3. Statements and Expressions
4. Comments
A Simple Java Program: “Hello, World!”
public class HelloWorld {
10
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Explanation:
• public class HelloWorld: This declares a class named HelloWorld. Every Java
program must have at least one class.
• public static void main(String[] args): This is the main method where
program execution begins. The JVM (Java Virtual Machine) looks for this method
to start the application.
• System.out.println("Hello, World!");: This line prints the message to
the console. It's a standard output statement.
• {}: Curly braces define the body of classes and methods.
11
3. Statements:
Statements in Java end with a semicolon (;). For example:
java
System.out.println("Hello");
4. Braces and Indentation:
Code blocks are enclosed within curly braces {}. Proper indentation improves
readability but is not syntactically required.
5. Case Sensitivity:
Java is case-sensitive. For example:
• System and system are different identifiers.
• main must be lowercase; Main will not be recognized.
6. Comments:
Used to explain code.
// This is a single-line comment
/* This is a
multi-line comment */
7. Identifiers and Naming:
• Class names: Start with uppercase (e.g., HelloWorld)
• Variable/method names: Start with lowercase (e.g., myVariable, printData)
• Must not use reserved keywords (like int, class, public) as names.
…………………………………
12
• The language they created was originally called Oak, named after an oak tree
outside Gosling's office.
• However, Oak was later renamed to Java in 1995 due to trademark issues (the
name Oak was already in use).
1995 – Java’s Public Launch
• Java was officially launched by Sun Microsystems in 1995.
• It was introduced with the slogan: “Write Once, Run Anywhere” (WORA).
• The idea was that Java programs could run on any device or operating system
that had the JVM installed, without modification.
• Java quickly gained popularity due to its portability, simplicity, and security
features.
1996 – First Official Java Version (JDK 1.0)
• Sun released the first version of Java Development Kit (JDK 1.0) in 1996.
• This included core classes, JVM, and development tools like javac and java.
• Java was mainly used for web applets embedded in browsers during the early
internet era.
Late 1990s – Java’s Rise
• Java became widely adopted for building web applications, enterprise
software, and mobile apps.
• Java 2 (J2SE, J2EE, and J2ME) was introduced, separating the platform into
different editions:
➢ J2SE (Standard Edition) for desktop applications
➢ J2EE (Enterprise Edition) for large-scale business applications
➢ J2ME (Micro Edition) for mobile and embedded devices
2006 – Java Becomes Open Source
• In 2006, Sun Microsystems made Java open-source under the GNU General
Public License (GPL).
• This move led to the creation of OpenJDK, the official open-source version of
Java.
2010 – Oracle Acquires Sun Microsystems
• In January 2010, Oracle Corporation acquired Sun Microsystems.
• This gave Oracle control over Java and its future development.
13
Role of Sun Microsystems in Java Development
Sun Microsystems played a foundational role in the creation and early success of Java:
• Invented and developed Java: James Gosling, working at Sun, is credited as the
"father of Java".
• Released Java to the public in 1995, making it available for developers
worldwide.
• Promoted the concept of "Write Once, Run Anywhere", which became Java's
key advantage.
• Developed the Java Development Kit (JDK), Java Runtime Environment (JRE),
and Java APIs.
• Supported and updated Java through the 1990s and early 2000s, making it a
standard in web and enterprise application development.
• Introduced the Java Community Process (JCP), allowing developers and
organizations to contribute to the evolution of Java specifications.
Sun was known for its innovation and open-source vision, which helped Java grow into
one of the most popular languages globally.
14
6. JVM, JRE, and JDK
1. Java Virtual Machine (JVM)
Definition:
The Java Virtual Machine (JVM) is an abstract computing machine that enables a
computer to run a Java program. It interprets or compiles Java bytecode into machine
code so that it can be executed on the host system.
Key Features:
• Platform-independent: Java programs can run on any OS that has a JVM
installed.
• Performs runtime tasks: Memory management (via garbage collection),
security, and bytecode execution.
• It does not include development tools like compilers or debuggers.
Function:
• The JVM reads compiled .class files (bytecode) and executes them.
• It acts as the execution engine of Java.
2. Java Runtime Environment (JRE)
Definition:
The Java Runtime Environment (JRE) is a software package that provides the
libraries, Java class files, and JVM required to run Java applications.
Key Features:
• It contains:
➢ JVM
➢ Java class libraries
➢ Other files needed to run Java programs
• Does not include tools to create Java programs like the compiler (javac).
Function:
• JRE provides everything needed to execute already compiled Java programs.
• Ideal for users who only want to run Java applications, not develop them.
3. Java Development Kit (JDK)
Definition:
15
The Java Development Kit (JDK) is a full-featured software development kit used to
develop Java applications. It includes everything in the JRE plus development tools.
Key Features:
• It contains:
➢ JRE (including JVM and class libraries)
➢ Development tools: javac (Java compiler), java (launcher), javadoc, jar,
etc.
• Required for writing, compiling, debugging, and running Java code.
Function:
• JDK is used by developers to create and build Java applications.
• Once code is written and compiled into .class files, those files can be run using
JRE.
How JVM, JRE, and JDK Work Together
Let’s go through the Java program execution process:
1. Write the Java code using any text editor or IDE like IntelliJ or Eclipse.
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
2. Compile the code using the JDK (specifically, the javac compiler).
bash
javac Hello.java
This creates a bytecode file: Hello.class.
3. Execute the bytecode using the JVM, which is part of the JRE:
bash
java Hello
The JVM loads the .class file, verifies it, and translates it into machine-specific code
using the interpreter or JIT compiler, then executes it.
…………………………………
17
2. Memory Consumption
Java applications require more memory compared to lower-level languages. This
is partly due to its object-oriented nature and the overhead of the JVM and
garbage collector.
3. Verbose Syntax
Java’s syntax can be lengthy and repetitive. Simple operations often require more
code in Java compared to modern languages like Python or Kotlin, which can
reduce productivity for small-scale or scripting tasks.
4. No Support for Low-Level Programming
Java does not support low-level programming tasks such as pointer
manipulation or direct hardware access. This makes it unsuitable for systems
programming or performance-critical tasks that need fine control over memory.
5. Complex GUI Development
Although Java provides GUI libraries like AWT and Swing, these are considered
outdated and less intuitive than modern frameworks available in other
languages. JavaFX is an alternative, but its adoption is limited.
6. Licensing Changes for Oracle JDK
Starting with Java 11, Oracle introduced a commercial licensing model for the
Oracle JDK. This led to concerns in the developer community and increased the
use of alternatives like OpenJDK.
…………………….The End…………………….
18