Department of CSDS
Course Code: BCS403
Course Name: OOP with Java
UNIT – 1 (INTRODUCTION)
CREATED BY K. VICTOR BABU
Course Outcomes
CO1 Develop the object-oriented programming concept using Java
Implement exception handling, file handling and multi-threading in
CO2 Java
CO3 Apply new Java features to build java programs
CO4 Analyse Java programs with collection Framework
Test web and RESTful web services with spring boot using Spring
CO5 Framework concepts
CREATED BY K. VICTOR BABU
Course Prerequisites
• Basic Programming Concepts
• Procedural Programming
• Understanding Algorithms and Problem Solving
• Memory Management
• Data Structures
• Basic Command-Line Usage
• Understanding of Databases
CREATED BY K. VICTOR BABU
Syllabus
Unit - 1
• Introduction: Why Java, History of Java, JVM, JRE, Java Environment, Java Source
File Structure, and Compilation. Fundamental,
• Programming Structures in Java: Defining Classes in Java, Constructors, Methods,
Access Specifies, Static Members, Final Members, Comments, Data types, Variables,
Operators, Control Flow, Arrays & String.
• Object Oriented Programming: Class, Object, Inheritance Super Class, Sub Class,
Overriding, Overloading, Encapsulation, Polymorphism, Abstraction, Interfaces, and
Abstract Class.
• Packages: Defining Package, CLASSPATH Setting for Packages, Making JAR Files
for Library Packages, Import and Static Import Naming Convention For Packages
CREATED BY K. VICTOR BABU
Lecture Objectives
To understand Java data types, variables, Control Flow, Operators,
Methods and Access Specifiers for java program. The application and
functionality of above concepts in java programs.
CREATED BY K. VICTOR BABU
Lecture Outcomes
Develop the object-oriented programming concept using Java
CREATED BY K. VICTOR BABU
Why Java
Java is a powerful, class based, object oriented, multipurpose,
versatile programming language. Its robust design,
cross-platform compatibility, and extensive library of tools and
frameworks make it a popular choice for developers
A worldwide.
a
CREATED BY K. VICTOR BABU
History of Java
•Java was created at Sun Microsystems, Inc., where James
Gosling led a team of researchers in an effort to create a new
language that would allow consumer electronic devices to
communicate with each other. Work on the language began in
1991, and before long the team’s focus changed to a
new niche, the World Wide Web. Java was first released in
1995, and Java’s ability to provide interactivity and
multimedia showed that it was particularly well suited for the
Web.[1]
CREATED BY K. VICTOR BABU
History of Java
CREATED BY K. VICTOR BABU
Object Oriented Programming
• The object-oriented programming is basically a computer programming
design philosophy or methodology that organizes/ models software design
around data, or objects rather than functions and logic.
• An object is referred to as a data field that has unique attributes and
behaviour. Everything in OOP is grouped as self-sustainable objects.
• It is the most popular programming model among developers. It is well
suited for programs that are large, complex, and actively updated or
maintained. It simplifies software development and maintenance by
providing major concepts such as abstraction, inheritance, polymorphism,
and encapsulation. These core concepts support OOP.
CREATED BY K. VICTOR BABU
Features of OOP - Java
CREATED BY K. VICTOR BABU
Features of OOP - Java
• Platform independent: Unlike many other programming
languages including C and C++, when Java is compiled, it is not
compiled into platform specific machine, rather into platform
independent byte code. This byte code is distributed over the web
and interpreted by virtual Machine (JVM) on whichever platform it
is being run.
• Simple: Java is designed to be easy to learn. If you understand
the basic concept of OOP, Java would be easy to master.
CREATED BY K. VICTOR BABU
Features of OOP - Java
• Secure: With Java's secure feature, it enables to develop virus-free,
tamper-free systems. Authentication techniques are based on
public-key encryption.
• Architectural-neutral: Java compiler generates an
architecture-neutral object file format, which makes the compiled
code to be executable on many processors, with the presence of
Java runtime system.
• Portable: Being architectural-neutral and having no
implementation dependent aspects of the specification makes Java
portable. Compiler in Java is written in ANSI C with a clean
portability boundary which is a POSIX subset.
CREATED BY K. VICTOR BABU
Features of OOP - Java
• Robust: Java makes an effort to eliminate error prone situations
by emphasizing mainly on compile time error checking and
runtime checking.
• Multithreaded: With Java's multithreaded feature, it is possible to
write programs that can do many tasks simultaneously. This
design feature allows developers to construct smoothly running
interactive applications.
• Interpreted: Java byte code is translated on the fly to native
machine instructions and is not stored anywhere. The development
process is more rapid and analytical since the linking is an
incremental and lightweight process.
CREATED BY K. VICTOR BABU
Features of OOP - Java
• High Performance: With the use of Just-In-Time compilers, Java
enables high performance.
• Distributed: Java is designed for the distributed environment of
the internet.
• Dynamic: Java is considered to be more dynamic than C or C++
since it is designed to adapt to an evolving environment. Java
programs can carry extensive amount of run-time information that
can be used to verify and resolve accesses to objects on run-time.
CREATED BY K. VICTOR BABU
Object Oriented Programming Concepts - Java
There are some basic concepts that act as the building blocks
of OOPs i.e.
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link] Binding
[Link] Passing
CREATED BY K. VICTOR BABU
Concepts
Class Objects
A class in Java is a blueprint for creating Objects are instances of a class. They
objects. It defines the data and methods represent concrete entities and have
within the objects. The class acts as a characteristics and behavior defined by the
template from which individual instances or class. Object-oriented programming uses
objects are created. objects to model and manipulate data
structures.
Encapsulation Abstraction
Encapsulation is the concept of wrapping Abstraction focuses on the essential
data (variables) and code acting on the data characteristics of an object, ignoring the
(methods) into a single unit. It protects the details. It simplifies the complexity, making
members of a class from external the programming process more manageable
interference and misusage. and understandable.
Polymorphism Inheritance
Polymorphism allows objects of different Inheritance allows a class to inherit the
classes to be treated as objects of a common properties and methods of another class. It
superclass. It enables a single action or supports the reusability of code and is a
behavior to be performed in different ways fundamental concept in OOP.
for different objects.
Dynamic Message Passing
Binding
Dynamic binding refers to the process of Message passing is a form of
linking a method call with the method body communication used in OOP. It refers to
at runtime. It allows the system to resolve the process of invoking a method in an
method calls at runtime, enabling object for the execution of a task.
extensibility and flexibility in code
CREATED BY K. VICTOR BABU
development.
An Object Oriented Programming Language
Object-oriented programming (OOP) is a computer programming design philosophy that organizes software design
around data and objects instead of functions and logic. In OOP, an object is a data field with unique attributes and
behavior. Everything is grouped as self-sustainable objects, making it well-suited for large, complex, and actively updated
or maintained programs. OOP simplifies software development and maintenance by providing major concepts such as
abstraction, inheritance, polymorphism, and encapsulation, which are fundamental to OOP.
CREATED BY K. VICTOR BABU
Java Program Running Structure
CREATED BY K. VICTOR BABU
JAVA Program
Structure
When a Java program runs, it undergoes a specific
structure that is essential for its execution. The Java
program running structure involves several important
components that ensure the proper functioning of the
program. The components include the Java Virtual
Machine (JVM), the ClassLoader, and the Execution
Engine. Each of these components plays a crucial role in
the execution the
Additionally, of the program,
structure ensuring
includes that the
a detailed code is
process of
loaded,
memoryverified, and executed
allocation, objecteffectively.
instantiation, method
invocation, and stack and heap management.
Understanding the intricacies of the Java program
running structure is fundamental for developers and
engineers to build efficient and effective Java
applications.
CREATED BY K. VICTOR BABU
Java Code
CREATED BY K. VICTOR BABU
Java Source File
Architecture
Java source code is stored in text
files with the .java extension. Each
Java file contains a single public
class or a collection of related
classes. The class name must
match the file name, and the file
must be located in a directory
structure that mirrors the package
hierarchy.
CREATED BY K. VICTOR BABU
Java Compilation
Process
Source Code
The Java development process begins with writing Java source code in a
text editor or IDE.
Compilation
The Java compiler takes the source code and translates it into Java
bytecode, an intermediate language.
Class File
The compiled bytecode is stored in a .class file, which can be executed by
the Java Virtual Machine.
CREATED BY K. VICTOR BABU
Java Bytecode
1 Intermediate 2 Compact and
Representation
Java bytecode is an intermediate Efficientis more compact and efficient
Bytecode
representation of the Java source code. than the original Java source code,
It is a low-level, platform-independent allowing for faster execution and
representation that can be efficiently smaller file sizes when distributing Java
executed by the Java Virtual Machine applications.
(JVM).
3 Portability 4 JVM
Because bytecode is Interpretation
The JVM interprets the bytecode and
platform-independent, Java applications translates it into native machine code
can run on any system that has a JVM that can be executed by the computer's
installed, without the need for processor, enabling the platform
recompilation. independence of Java.
CREATED BY K. VICTOR BABU
Java Platform
Independence
Write Once
1 Java code is written once and can run on different
platforms
Run Anywhere
2 Java applications can execute on any operating
system with a Java Virtual Machine
Java Virtual
3 Machine
The JVM acts as a layer between the Java
application and the underlying
hardware/OS
Java's platform independence is one of its key advantages. Java code can be written once and then
executed on a wide range of devices and operating systems, thanks to the Java Virtual Machine
(JVM) that acts as an intermediary between the application and the underlying hardware and
software.
CREATED BY K. VICTOR BABU
Java Virtual Machine
(JVM)
The Java Virtual Machine (JVM) is the runtime
environment that executes Java bytecode. It provides
a platform-independent way to run Java applications,
shielding developers from the underlying hardware
and operating system.
The JVM handles tasks such as memory management,
garbage collection, and just-in-time (JIT) compilation,
ensuring efficient and secure execution of Java code
on any compatible system.
CREATED BY K. VICTOR BABU
JVM (Java Virtual Machine)
1. A specification where working of Java Virtual Machine is specified. But implementation provider is
independent to choose the algorithm. Its implementation has been provided by Oracle and other
companies.
2. An implementation Its implementation is known as JRE (Java Runtime Environment).
3. Runtime Instance Whenever you write java command on the command prompt to run the java class, an
instance of JVM is created.
What it does
• The JVM performs following operation:
• Loads code
• Verifies code
• Executes code
• Provides runtime environment
JVM provides definitions for the:
• Memory area
• Class file format
• Register set
• Garbage-collected heap
• Fatal error reporting etc
CREATED BY K. VICTOR BABU
JVM (Java Virtual
Machine)
A An Runtime Operation of
Specification
A specification Implementat Instance the JVM
provides the ion
Its implementation When a java • Loads code
working of the is known as JRE command is • Verifies
Java Virtual (Java Runtime executed on the • code
Executes
Machine. It Environment), command prompt • code
Provides
specifies the rules which is an to run a java class, runtime
and functionalities essential part of an instance of JVM • Manages
environme
of the JVM. the Java runtime is created. This memory
nt
However, the system. It consists instance of JVM is area and
of Java Application responsible for • Defines
implementation garbage-co
Enumerator, translating Java the class
provider is llected
runtime libraries, bytecode into file format
independent to heap
• Handles
and the Java action or directly and
choose the
fatal error
Virtual Machine. running Java register set
algorithm. Major
reporting
companies like These components bytecode,
Oracle and other are required to run depending on the
software Java programs and implementation
developers have are necessary to provided by the
provided their own provide the JVM. It is crucial
implementation of runtime for the for the execution
the JVM Java programs. of Java-based
specification. applications and
CREATED BY K. VICTOR BABU
programs.
Java Runtime Environment
(JRE)
The Java Runtime Environment (JRE) is the software package that enables a
computer to run Java applications. It includes the Java Virtual Machine (JVM),
which is responsible for executing Java bytecode, and the core Java libraries
and components required for Java programs to function.
The JRE provides the necessary runtime environment and tools for Java
developers to deploy their applications. It ensures platform independence by
allowing Java programs to run on any operating system that has a compatible
JRE installed.
CREATED BY K. VICTOR BABU
JRE (Java Runtime
Environment
The Java Runtime Environment (JRE) is an essential software that Java
programs require to run effectively. It serves as the connector between Java
applications and the operating system, providing the necessary resources
for seamless execution on any computer platform without the need for
extensive modifications. The JRE acts as a translator and facilitator,
offering access to memory and other system resources, including program
files and dependencies.
Historically, most software relied on the operating system as its runtime
environment, necessitating the development of different code for various
operating systems. However, the JRE technology was introduced to address
this issue, enabling the development of platform-independent Java
software.
As one of the Java platform components, the JRE is critical for the
successful execution of any Java program. Together with the Java
Development Kit (JDK) and the Java Virtual Machine (JVM), it forms an
integral part of the Java ecosystem, supporting the functionality and
portability of Java applications.
CREATED BY K. VICTOR BABU
JRE (Java Runtime Environment)
The Java Runtime Environment (JRE) is software that Java programs require to run
correctly. Java is a computer language that powers many current web and mobile
applications. The JRE is the underlying technology that communicates between the
Java program and the operating system. It acts as a translator and facilitator, providing
all the resources so that once you write Java software, it runs on any operating system
without further modifications.
A software program needs a runtime environment that provides access to memory and
other system resources such as program files and dependencies. In the past, most
software used the operating system directly as its runtime environment. However, this
meant that developers had to write different code for each operating system that they
wanted their applications to run on. The Java Runtime Environment (JRE) technology
was created as a solution to this problem.
The JRE is actually one of three Java platform components that are required for any
Java program to run successfully. The Java Development Kit (JDK) and Java Virtual
Machine (JVM) are the other two components.
CREATED BY K. VICTOR BABU
JIT (Just in Time) Compiler
• The Just-In-Time (JIT) compiler is a component of the runtime
environment that improves the performance of Java™ applications by
compiling bytecodes to native machine code at run time.
• Java programs consists of classes, which contain platform-neutral
bytecodes that can be interpreted by a JVM on many different computer
architectures. At run time, the JVM loads the class files, determines the
semantics of each individual bytecode, and performs the appropriate
computation. The additional processor and memory usage during
interpretation means that a Java application performs more slowly than a
native application. The JIT compiler helps improve the performance of
Java programs by compiling bytecodes into native machine code at run
time.
CREATED BY K. VICTOR BABU
JIT
JIT Compiler Class Files Performance
The Just-In-Time (JIT) Java programs are composed Optimization
compiler is a crucial of classes, which contain The JIT compiler contributes
component of the Java platform-neutral bytecodes. At to performance optimization
runtime environment. It run time, the JVM loads these by converting bytecodes into
enhances the performance of class files, interprets the native machine code, thereby
Java™ applications by semantics of each bytecode, reducing processing overhead.
dynamically compiling and performs the necessary This enhances the execution
bytecodes into native machine computations. However, the speed of Java programs and
code at run time. This process additional processor and improves their overall
optimizes and accelerates the memory usage during performance relative to purely
execution of Java programs by interpretation can lead to interpreted bytecodes.
reducing the processing slower performance compared
overhead involved in bytecode to native applications.
interpretation.
CREATED BY K. VICTOR BABU
Java Environment
• Windows 10 and Windows 8
1. In Search, search for and then select: System (Control Panel)
2. Click the Advanced system settings link.
3. Click Environment Variables. In the section System Variables find
the PATH environment variable and select it. Click Edit. If the PATH environment variable
does not exist, click New.
4. In the Edit System Variable (or New System Variable) window, specify the value of
the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
5. Reopen Command prompt window, and run your java code.
• Solaris and Linux
1. To find out if the path is properly set:
In a terminal windows, enter:
% java -version
This will print the version of the java tool, if it can find it. If the version is old or you get the
error java: Command not found then the path is not properly set.
2. Determine which java executable is the first one found in your PATH
In a terminal window, enter:
% which java
CREATED BY K. VICTOR BABU
Java Environment
Java Environment
When setting up the Java environment on Windows 10 and Windows 8, you need to follow the
steps below:
In Search, search for and then select System (Control Panel)
Click the Advanced system settings link.
Click Environment Variables
In the section System Variables, find the PATH environment variable and select it. Click Edit. If
the PATH environment variable does not exist, click New.
In the Edit System Variable (or New System Variable) window, specify the value of
the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
Reopen Command prompt window, and run your java code.
When configuring the Java environment on Solaris and Linux, follow these instructions:
1. To find out if the path is properly set: In a terminal window, enter: % java -version. This will
print the version of the java tool, if it can find it. If the version is old or you get the error java:
Command not found, then the path is not properly set.
2. Determine which java executable is the first one found in your PATH. In a terminal window,
enter: % which java.
CREATED BY K. VICTOR BABU
Java Source File Structure
• Package Statement: In Java, a package is a way to gather together classes, sub
packages, and interfaces.
• Import Statements: A package, class, or interface is imported using an import
statement.
• Class Definition: A class is a passive entity that serves as a user-defined blueprint
or template from which objects are formed.
CREATED BY K. VICTOR BABU
Java Garbage
Collection
Automatic Concurrent Generational Customizable
Memory Execution Approach Behavior
Management Modern garbage Java's garbage Developers can
Java's garbage collectors can run collector employs fine-tune the
collection concurrently with a generational garbage collection
automatically the main model, focusing behavior by
frees up memory application, on the collection configuring
occupied by minimizing the of short-lived parameters like
objects that are no performance objects first, which heap size,
longer in use, impact of the are more collection
relieving collection process. common, frequency, and
developers from improving overall collection
the burden of efficiency. algorithm to
manual memory optimize
management. performance for
their specific use
CREATED BY K. VICTOR BABU case.
Java Security
Features
Access Control Bytecode
Java provides robust access control Verification
The Java Virtual Machine (JVM) verifies the
mechanisms to ensure data and bytecode to ensure it adheres to Java's
application security, with features like type-safety rules, preventing unauthorized
access modifiers, security managers, and code execution.
permissions.
Sandboxing Cryptography
Java's sandbox model isolates applets and Java includes a comprehensive
untrusted code, restricting their access to cryptography framework, enabling secure
system resources and preventing them communication, data encryption, and
from causing harm. digital signatures for enhanced application
security.
CREATED BY K. VICTOR BABU
Recommended Books
1. Steven Holzner, “Java Black Book”, Dreamtech.
2. Balagurusamy E, “Programming in Java”, McGraw Hill
3. Java: A Beginner’s Guide by Herbert Schildt, Oracle Press
4. Greg L. Turnquist “Learning Spring Boot 2.0 - Second Edition”, Packt Publication
CREATED BY K. VICTOR BABU
THANK YOU
Team – OOPs with Java
CREATED BY K. VICTOR BABU