0% found this document useful (0 votes)
10 views12 pages

OOP with java unit 1

This document provides an overview of Java, a prominent object-oriented programming language introduced in 1995, highlighting its features, history, and architecture. Key aspects include Java's platform independence, security features, and the role of the Java Virtual Machine (JVM) in executing Java applications. Additionally, it details the components of the Java Development Kit (JDK) and Java Runtime Environment (JRE), essential for developing and running Java programs.

Uploaded by

sapna842004
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)
10 views12 pages

OOP with java unit 1

This document provides an overview of Java, a prominent object-oriented programming language introduced in 1995, highlighting its features, history, and architecture. Key aspects include Java's platform independence, security features, and the role of the Java Virtual Machine (JVM) in executing Java applications. Additionally, it details the components of the Java Development Kit (JDK) and Java Runtime Environment (JRE), essential for developing and running Java programs.

Uploaded by

sapna842004
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/ 12

Object Oriented Programming With JAVA

Chapter-1

Introduc on to JAVA

Introduction

Java, a renowned programming language introduced in 1995 by Sun Microsystems


(now part of Oracle Corporation), remains a
cornerstone in the tech industry. Its high-level, Introduc on
object-oriented design promotes platform  History of Java
independence, allowing Java code to run  Feature of Java
seamlessly on any device equipped with a Java  Architecture
Virtual Machine (JVM). This feature is encapsulated JRE
in the principle "Write Once, Run Anywhere"  Components
(WORA). JVM
JDK
As an object-oriented language, Java  Components
provides a robust framework for developing logical
 Tools Used
and efficient software, significantly reducing
JVM vs JRE vs JDK
development costs through reusable code. Its
Environmental Setup
similarity to C++ and C# eases the transition for Applica ons of Java
software engineers, making it an attractive choice for
many professionals. Java's versatility allows it to
operate across multiple operating systems, such as Windows, Mac, Linux, and even the
Raspberry Pi.

Desktop
Application

Mobile Apps Websites

Java

Games Web Servers

Database
Connections

With widespread recognition and a strong presence in the tech job market, Java
remains one of the most in-demand programming languages worldwide. It is lauded for its
Object Oriented Programming With JAVA
ease of learning and user-friendly nature. As an open-source language, Java is accessible and
free, offering a secure, fast, and powerful development environment. Supported by a vibrant
community of millions of developers, Java is employed in creating a vast array of applications
and software solutions.

History of Java
In 1991, James Gosling, along with his colleagues at Sun Microsystems Lab, invented
Java. Originally conceived for interactive television, Java was ahead of its time, offering
complexity that the market wasn't ready to embrace. Initially called "Oak," named after an oak
tree outside Gosling's office, the project was eventually renamed "Java" inspired by Java coffee.
The innovation's journey began with the Green Team, a group of pioneering engineers
developing this sophisticated language for digital devices like televisions and set-top boxes.

Although the original idea was innovative for its time, Java found its true potential in
online programming. This led to its integration by Netscape, marking the beginning of Java's
widespread adoption. Today, Java is a cornerstone in diverse applications such as e-commerce,
gaming, mobile technology, and web development. Key milestones in Java's evolution include:

1991 1995 1997 1998


Birth of Java Official launch of JCP (for open Introduc on
as the Green java applets collabora on), JDK of Java 2
project revolu onizes web 1.1, and JVM (SE, EE, ME)
development standardiza on begins

2014 2009 2006 2004


Java 8 introduces Oracle acquires Sun Java becomes open- Java 5-adds generics,
Lambdas, Stream API, Microsystems (takes source under the GNU annota ons, and
and Date- me API over Java) General public License enhanced for- loop

2017 2021 2023


Java 9 introduces Java 17 LTS version Java 20 & 21
modules (project released with refine virtual
jigsaw) performance threads and
improvements tools

1. The Birth of Java: In June 1991, James Gosling, Mike Sheridan, and Patrick Naughton
initiated the Java language project. They were part of the Green Team, a small group focused
on solar engineering solutions.
Object Oriented Programming With JAVA
2. Early Design Focus: Java was initially designed for embedded systems in electronic gadgets
like set-top boxes.
3. Initial Naming: The language was first called "Greentalk," represented by the file
extension.gt.
4. Evolution and Growth: After its early development, Java was rebranded from "Oak" to
"Java". Since its introduction in the mid-1990s, Java has undergone significant evolution. Each
version brings new features, improved security measures, and enhanced performance.
As of now, multiple Java versions have been released, each contributing to the language's
robust functionality and staying power in the tech industry.

Features of Java
Java offers a range of features that make it a popular choice for developers. Below, we
detail the key features of Java, emphasizing its benefits and strengths.

Key Features of Java


Object Oriented Programming With JAVA
1.Object-Oriented-Java is a pure object-oriented programming language, meaning it
centres around objects and classes. By adopting the object-oriented programming (OOP)
paradigm, Java promotes modularity and code reusability. This approach helps developers

Simple

Object
Interpreted
oriented

Dynamic Distributed

Architectural Features Multithreded


Neutral of java

Plateform
Portable
independent

High
Rubust
performance

Secured

write reusable, scalable, and maintainable code by organizing data and behaviours into
objects.

2.Platform-Independent-Java's platform independence is one of its standout


features. Thanks to the Java Virtual Machine (JVM), Java programs can run on various operating
systems like Windows, Linux, and macOS without modification. Java code is compiled into
bytecode, which the JVM executes, ensuring it is not tied to specific hardware.

3.Secure-Java’s security features make it a preferred choice for web applications,


enterprise software, and banking systems. Java runs inside the JVM, preventing direct
interaction with the operating system. Its security is bolstered by bytecode verification,
automatic memory management, garbage collection, and strict access controls using
classloaders and security managers.

4.Simple and Robust-Java is designed to be simple and robust, eliminating


complexities seen in languages like C/C++. It simplifies coding by removing features like
explicit pointers and automates memory management through garbage collection, thereby
enhancing code stability and reliability.
Object Oriented Programming With JAVA
5.Multi-threaded-Java supports multi-threading, allowing the concurrent execution
of multiple tasks. This enhances the performance, responsiveness, and efficiency of Java
applications, making it ideal for modern computing needs.

6.Portable-Java's portability is unparalleled. Once written, Java code can run on any
device with a JVM, as it is compiled into hardware-independent bytecode (.class files). This
cross-platform capability is a significant advantage over other programming languages.

7.High Performance-Java achieves high performance through various optimizations


such as Just-In-Time (JIT) compilation, efficient memory management, and multi-threading.
These features ensure that Java programs run efficiently despite being interpreted.

8. Architecture-Neutral-Java is architecture-neutral, meaning programs are not


dependent on processor architecture. This is achieved through its bytecode and JVM, ensuring
that Java applications are compatible across various hardware and operating systems.

9. Dynamic-Java's dynamic nature allows for runtime modifications, flexible memory


management, and dynamic class loading. This adaptability makes Java ideal for evolving
environments, modern applications, web development, and distributed systems.

10.Interpreted Language - Java is renowned as an interpreted language because it


doesn't produce machine-specific code directly. Instead, Java programs are compiled into
bytecode. This bytecode is subsequently interpreted and executed by the Java Virtual Machine
(JVM), ensuring cross-platform compatibility.

11.Distributed Programming- Java is inherently distributed, designed to facilitate


network-based applications and enable programs to operate seamlessly across multiple
systems. This characteristic makes Java a perfect choice for cloud computing, web applications,
and enterprise software development.

JVM (Java Virtual Machine)


The Java Virtual Machine (JVM) is the powerful engine behind all Java applications,
efficiently converting Java bytecode into machine code that is easily understood by the
operating system. Serving as a crucial component of the Java Runtime Environment (JRE), the
JVM provides a robust runtime environment for running Java code and applications. Unlike
other programming languages where the compiler produces machine code tailored to a
specific system, Java compiles code for a virtual platform, the JVM, ensuring greater portability
and compatibility across diverse systems.

Features of JVM

a) Converts Java bytecode into native machine code.


b) Provides memory management functions such as trash collection.
c) Verifies bytecode before execution for increased security.
d) Supports platform independence, enabling Java's "Write Once, Run Anywhere" (WORA) fea
ture.
Object Oriented Programming With JAVA
JVM Architecture

Java's JVM architecture comprises essential components such as a class loader, memory
space, and an execution engine, among others. The key operations performed by the JVM
include:

(a) Loading code


(b) Verifying code
(c) Executing code
(d) Providing a runtime environment
These functions ensure the efficient and secure running of Java applications.
Understanding the JVM architecture is crucial for developers aiming to optimize their Java
applications' performance and reliability.

Class Loader Byte code Verifier Execution Engine

The image illustrates the Java Development Kit (JDK) workflow, emphasizing the Java Class
Loading and Execution Process within the Java Virtual Machine (JVM). In the given figure
detailed analysis of the components depicted in the image:

1. Class Loader-A Class Loader in Java is a critical component of the Java Runtime Environment
(JRE) that dynamically loads Java classes into memory during runtime. Following the
Delegation Hierarchy Model, it plays a vital role in the dynamic linking of classes. The Class
Loader efficiently performs three main functions: loading, linking, and initialization. This
process ensures that Java applications run smoothly by managing class loading seamlessly. By
understanding the role of a Class Loader, Java developers can optimize application
performance and enhance runtime efficiency.

The Class Loader is a crucial component in the Java execution process. Here's how it functions:
- It loads .class files (bytecode) into memory whenever a Java program is executed.
- Java offers several types of class loaders:
a) Bootstrap Class Loader: This loader handles the core Java classes, loading them
from the rt.jar or module path.

b) Extension Class Loader: Responsible for loading classes from the lib/ext directory.

c) Application Class Loader: Loads classes from the defined classpath.

The Class Loader ensures that all necessary classes are readily available for execution, playing
a vital role in running Java applications smoothly.
Object Oriented Programming With JAVA

Class loader
loading linking Ini a on

Memory Area of Java Na ve Interface

Method Heap Stack PC Na ve


method
Area area Area register stack
s

JNI Java Na ve
Na ve Method
Interface Library

Interpreter JIT compiler Garbage collector

2. Bytecode Verifier

When executing a Java program, the Java Virtual Machine (JVM) handles memory
dynamically by dividing it into various runtime memory areas. These areas are essential for
storing code, variables, objects, and methods during program execution.

One key component, the JVM Method Area, is responsible for housing class structures,
including metadata, the constant runtime pool, and method code.

Here’s how the process works:

a) Bytecode Loading and Verification: After the Java program loads, its bytecode enters
the Bytecode Verifier.
b) Security and Integrity Checks: The Bytecode Verifier ensures the security and integrity
of the program by:
a. Preventing illegal memory access.
b. Ensuring no stack underflows or overflows occur.
c. Verifying compliance with Java’s safety rules.
If the bytecode verification fails, a VerifyError is thrown, effectively preventing the execution of
potentially harmful code.
Object Oriented Programming With JAVA
3. Execution Engine

The Just-In-Time (JIT) Compiler significantly enhances performance and is a vital part of
the Java Virtual Machine (JVM), which executes bytecode. It processes .class files by
interpreting and transforming them into machine code that the CPU can execute efficiently.
After verification, the Execution Engine handles the bytecode conversion. Key Components of
the Java Virtual Machine:

a) Interpreter: Executes Java bytecode line by line, resulting in slower execution speeds.
b) JIT Compiler: Transforms bytecode into native machine code for faster execution,
boosting overall performance.
c) Garbage Collector: Automatically eliminates unused objects to free up memory. In Java,
objects are dynamically created in the Heap memory using the new keyword. However,
unused objects consume memory and may lead to an OutOfMemoryError. The Garbage
Collector efficiently identifies and clears these objects. The heap memory stores all objects
and their associated instance variables and arrays, shared by multiple threads.

For optimal JVM performance, understanding and leveraging these components, including the
JIT Compiler and Garbage Collector, is essential. By doing so, developers can ensure efficient
memory management and execution speed in Java applications.

JRE (Java Runtime Environment) - The Java Runtime Environment (JRE) is an


essential package designed specifically for executing Java programs. While it provides all the
necessary components to run Java applications, it does not include the tools required for
writing or compiling Java code, such as the Java compiler (javac). Therefore, JRE is solely
intended for running Java programs rather than developing them. Whether you're developing
or running Java applications, understanding these components ensures optimized
performance and a secure Java runtime environment.
Components of JRE
a) JVM – it is used for execution of Java bytecode.
b) Java Class Libraries – Pre-built Java classes for common functionalities (I/O,
networking, utilities).it includes predefined APIs like java.lang, java.util, etc.
c) Java Plugins – Support for running Java applications in web browsers. Configuration
and resource files required for execution.

Java Virtual Machine (JVM): The Java Virtual Machine (JVM) is a powerful engine
that creates a runtime environment for running Java code and applications. Its primary function
is to transform Java bytecode into machine language, allowing it to execute on any device with
a compatible JVM installation. Although termed as a "machine," the JVM exists solely within
the computer's memory. The process it follows includes these key steps:

1. Compiling Source Code: The javac compiler converts the high-level Java source code into
bytecode, which is a machine-readable format.
2. Executing Bytecode: A Java interpreter then takes this bytecode and translates it into
human-understandable instructions, allowing the program to run seamlessly.
Object Oriented Programming With JAVA

Classloader

ByteCode verifier

Interpreter

Run-Time

Hardware

Discover the comprehensive software package essential for running Java applications:

a) Bytecode Verifier-The Bytecode Verifier plays a crucial role in ensuring the integrity of
Java applications. It meticulously checks the format and accuracy of Java code before it
reaches the interpreter. If any code compromises system integrity or breaches access
rights, the class is deemed corrupt and will not be loaded, ensuring a secure runtime
environment.
b) Interpreter-Once the bytecode is successfully loaded, the Java Interpreter takes charge. It
constructs an object of the Java Virtual Machine (JVM), enabling the Java program to run
seamlessly on the host machine. This process ensures that your Java applications execute
natively and efficiently.
c) ClassLoader-The Java ClassLoader is a dynamic component responsible for loading all
necessary classes required for running a Java program. Enhancing efficiency, classes are
only loaded into memory when needed. This automated process is managed by the
ClassLoader, optimizing resources. During JVM initialization, three primary ClassLoaders
are activated:
1) Bootstrap ClassLoader: The foundational loader that loads core Java libraries.
2) Extensions ClassLoader: Handles the loading of standard Java extensions.
3) System ClassLoader: Manages classes specified by the user's classpath.

JDK (Java Development Kit)

The Java Development Kit (JDK) is an essential software development kit for developers
looking to create, compile, and run Java applications. As a cornerstone in Java development,
the JDK encompasses the Java Runtime Environment (JRE) along with additional tools
necessary for efficient Java programming, including the compiler (javac), debugger, and a suite
of utilities.

Components

1. JRE (Java Runtime Environment) – It is required to run Java applications.

2. JVM (Java Virtual Machine) – It executes compiled Java bytecode.


Object Oriented Programming With JAVA
3. Java Compiler– It converts Java source code (.java) into bytecode (.class).

4. Development Tools – It includes tools like javadoc, javap, jdb (Java Debugger).

5. Java Standard Libraries (API) – It includes pre-built classes (e.g., java.lang, java.util,
java.io).

JDK

JRE

JVM

Developers can choose between multiple versions provided by Oracle, such as the Oracle JDK,
which requires a commercial license for production but remains free for development
purposes, and the OpenJDK, which is open-source and free. The JDK is indispensable for Java
developers crafting various applications, whether for desktop, web, mobile, or enterprise
environments.

Integral to Java development, the JDK includes a comprehensive collection of tools designed
specifically for developing and executing Java programs. Notable tools within the JDK include:

JDK Tools Used for

Appletviewer The appletviewer is a web browser that is used to run java applets.
It is java interpreter that can analyse and executes your program line by
Java
line.
Javac It is a java compiler that can analyse and executes your whole program.
It is java disassembler that is used to translate machine code into a human
Javap
readable format.
It is used to generate C header (.h) files from Java classes and other
javah
programming files.
It generates HTML documentation for web-based applications from Java
Javadoc
source code.
jdb It is java debugger it is used in debugging the existing errors.

JVM vs. JRE vs. JDK

These three are the core components of the Java platform, but they serve different purposes
in the Java lifecycle. Let’s dive deeper into the differences and roles of JVM, JRE, and JDK with
a detailed explanation.
Object Oriented Programming With JAVA
JRE
JVM JDK
Feature (Java Runtime
(Java Virtual Machine) (Java Development Kit)
Environment)
Runs compiled Java Provides environment to For developing, compiling,
Installation
programs(bytecode) on execute Java applications. and running Java
Purpose
any platform. programs.
Java Virtual Machine JVM + Java libraries. JRE + Development tools
Contains
(JVM) Only (compiler, debugger, etc.)

Java Environment Setup

The Java Environment consists of various components that work together to write, compile,
and execute Java programs. The key elements of the Java environment are JDK (Java
Development Kit), JRE (Java Runtime Environment), and JVM (Java Virtual Machine). To set up
Java Development Environment you will need:

a) JDK Installation – Download and install from Oracle website or OpenJDK.


b) Environment Variables Setup – Set JAVA_HOME and update PATH.
c) Integrated Development Environment (Optional) – For easier development use an
IDE like Eclipse, IntelliJ IDEA, or VS Code.

To Verify your Java Installation Run the following commands in the terminal or command
prompt If Java is installed correctly, it will display the installed version:

Applications of Java

Java is a leading programming language renowned for its platform independence,


robust security features, scalability, and exceptional performance. Widely used across various
industries, Java shines particularly in web development. Powerful frameworks like Spring,
Struts, and Hibernate enable the creation of dynamic websites and responsive web
applications. Java Server Pages (JSP) and Servlets further enhance the development of scalable,
secure, and high-performance web solutions, making Java ideal for sectors like e-commerce
and finance.

In mobile app development, Java plays a pivotal role as the foundation for Android
applications. Officially supported by Android Studio, Java's extensive libraries and active
community make it a popular choice for developing a wide array of Android apps, including
Object Oriented Programming With JAVA
those in banking and social media. Whether for creating a seamless e-commerce experience
or powering the latest social media platform, Java continues to be a top choice for developers
worldwide.

Java Applications
Java plays a pivotal role in web development by powering dynamic websites and
1 applications. Popular Java frameworks such as Spring, Hibernate, Struts, and
JavaServer Faces (JSF) are often employed to streamline the development process.
For mobile app development, particularly Android applications, Java remains a
dominant choice. With tools like Android SDK and Android Studio, developers can
2
create feature-rich and performant Android apps, capitalizing on Java’s reliability and
extensive community support.
In the realm of enterprise applications, Java brings stability and security, making it a
top choice for industries such as banking, healthcare, insurance, and logistics.
3 Frameworks like Spring Boot and Java EE (Enterprise Edition) are commonly used to
build scalable and secure enterprise solutions that can handle complex business
processes.
Java’s cross-platform nature is perfect for creating desktop applications, utilizing GUI
frameworks such as JavaFX, Swing, and AWT. Developers frequently use Integrated
4
Development Environments (IDEs) like IntelliJ IDEA, Eclipse, and NetBeans to enhance
their programming efficiency and productivity.
Java's scalability makes it ideal for developing cloud-based applications. Leading cloud
platforms such as Amazon Web Services (AWS), Google Cloud, and Microsoft Azure
5
host Java applications, which are often deployed as Software as a Service (SaaS) and
Platform as a Service (PaaS) solution.
Java is integral to big data and real-time analytics, processing massive datasets
efficiently with frameworks like Apache Hadoop and Apache Spark. These tools enable
6
businesses to derive valuable insights from data, bolstering informed decision-making
processes.
In the Internet of Things (IoT) landscape, Java is utilized for developing applications for
7 embedded systems and smart devices, including smart homes, wearables, and
industrial automation.
Java's versatility extends to game development across desktop, online, and mobile
8 platforms. Notable games like Minecraft illustrate Java’s capability to support rich
graphics and interactive experiences.
Java plays a crucial role in artificial intelligence (AI) and machine learning applications,
including chatbots, natural language processing (NLP), and image recognition.
9
Popular Java libraries, like DeepLearning4J and Weka, support these functions, making
Java an essential language for AI development.
Java is widely used in network security and data protection. It is instrumental in
implementing secure authentication and encryption methods to safeguard sensitive
10
information. With its versatility and robust security features, Java remains a top choice
for developers in both AI and cybersecurity fields.

You might also like