Unit 1 OOP Elements
Unit 1 OOP Elements
PROGRAMMING
Dr. M. ANBAZHAGAN
Unit 1
Structured to Object Oriented Approach by Examples - Object Oriented
languages - Properties of Object Oriented system – UML and Object-
Oriented Software Development - Use case diagrams and documents
as a functional model – Identifying Objects and classes -
Representation of Objects and its state by Object Diagram - Simple
Class using class diagram – Encapsulation - Data Hiding - Reading and
Writing Objects - Class Level and Instance Level Attributes and
Methods- JIVE environment for debugging.
OOP
Fundamentals
What is OOP?
Object-Oriented Programming is a programming paradigm that organizes
software design around objects, which are instances of classes. Objects
encapsulate data (attributes) and behavior (methods) into a single entity,
allowing for modular, reusable, and scalable code.
What is Object?
An object is a fundamental unit in Object-Oriented Programming that
represents a specific instance of a class, containing both data (attributes) and
behavior (methods). Objects are used to model real-world entities or
concepts in a structured and reusable way.
What is Class?
A class is a blueprint or template used to define the structure and behavior of
objects in Object-Oriented Programming (OOP). It specifies the attributes
(data) and methods (functions) that objects created from the class will have.
Structured to Object-oriented
• The evolution from structured to object-oriented programming represents
a significant shift in software development paradigms
Bottom-up Approach
Top-down Approach
Subfunction 1
Object 2
Subfunction 2
Object 1
⋮
Subfunction n Class
Top-down Vs. Bottom-up w.r.t Problem
Solving
Structured to Object-oriented
Development Class
Tools JVM Libraries
Java Development Kit (JDK)
• The all-in-one toolkit for Java developers
• It's the outermost layer in the ecosystem and contains everything needed
to develop, compile, debug, and run Java applications
• What Does the JDK Include?
Development Tools
The JDK comes with essential tools Java Runtime Environment (JRE)
such as the Java compiler (javac), the The JDK contains the JRE, allowing
debugger, and utilities that developers developers to run the code they write,
rely on to write and troubleshoot their all within the same environment
Java code
Java Runtime Environment (JRE)
• JRE is nested inside the JDK and represents the environment required to run
Java applications
• It's like the engine of a car that makes everything move once the pieces are in
place
• The JRE is perfect for those who don't need to develop Java programs but need to
run them
Class Loader
Native
Class Area Heap Stack PC Register Method
Stack
Execution Optimized with JIT Compiler Runs line by line, which is slower
Java Vs. Python
Typing System
Flexibility Less flexible; requires explicit types More flexible due to implicit typing
Garbage
Automatic Garbage Collection (JVM) Automatic Garbage Collection
Collection
Memory Usage More efficient for large applications Higher memory consumption
Java Vs. Python
Portability
Strong support for enterprise Strong support for AI, ML, and
Community
software scripting
Robust libraries for enterprise and Extensive libraries for data science,
Libraries
web ML, and automation
Java Vs. Python
• Java: Best suited for large-scale enterprise applications, Android
development, and applications requiring high performance and strict
typesafety
• Python: Preferred for data science, machine learning, AI, scripting, and
applications requiring faster development with simple syntax
OOP
Elements
Elements of OOP Model
Major Elements
Minor Elements
Abstraction
Strong Typing
Encapsulation
Concurrency
Inheritance
Modularity Persistence
Abstraction
Abstraction is a core principle of Object-Oriented Programming that focuses
on hiding implementation details and exposing only the essential features or
functionality of an object
Key Features of Abstraction
• Hiding Complexity
• Abstraction hides the "how" (implementation) and shows only the "what"
(functionality)
• For example, when you drive a car, you use the steering wheel to turn, but
you don’t need to understand how the steering mechanism works internally
• Essential Information Only
• It provides only the details necessary for the user and omits the unnecessary
ones
• Example: A List in Python or Java provides methods like add() and remove(),
but hides how the elements are stored internally
Types of Abstraction
Process/Control Elements
Data Abstraction
Hides the implementation details
Hides internal details about how
of control flow and provides a
data is stored or represented
simple interface to perform
E.g. A databases
complex operations
E.g. A sort function
Abstraction in OOP
Abstract Classes Interfaces
• An abstract class is a class that • An interface defines a contract or
cannot be instantiated directly blueprint for a class, specifying
and is meant to be subclassed what methods it should
• It may contain abstract methods implement
Bank Account
Balance You cannot directly change the
account balance; you must use
Deposit() controlled methods like deposit() or
Withdraw() withdraw()…!
Check_balance()
Abstraction Vs. Encapsulation
Abstraction is the process of Encapsulation is the process of
hiding the implementation bundling data and methods
details and showing only together and restricting direct
essential features access to data
Focuses on how the data and
Focuses on what an object does
methods are secured and
Abstract classes, interfaces, or organized
high-level method definitions Private fields, getters, setters,
Simplifies the complexity of a and access modifiers
system and provides a clear Ensures the integrity and security
interface of the data within an object
Inheritance
Inheritance is a fundamental principle of OOP that allows a class
(called the child class or subclass) to acquire the properties and
behaviors (methods) of another class (called the parent class or
superclass)
Class Hierarchy (is-a relationship)
• JAVA accomplishes inheritance by arranging all of its classes in a "family-
tree”- like ordering called a class hierarchy
• A class hierarchy is often represented as an upside down tree
• The more “general” kinds of objects are higher up the tree and the more
“specific” kinds of objects are below them in the hierarchy
Key Features of Inheritance
Hierarchy Polymorphism
Inheritance establishes a hierarchical With inheritance, subclasses can
relationship between classes, where override methods of the parent class,
subclasses derive from a base class enabling polymorphism
Types of Inheritance
Multiple Inheritance – A Glance
A child class inherits from multiple parent classes - This can lead to the
diamond problem
Modularity
• Modularity refers to the design principle of
breaking down a program into smaller,
manageable, and self-contained units or
modules
• Each module is designed to perform a
specific task and can be developed, tested,
and maintained independently
• Modularity makes complex systems easier
to understand, develop, and maintain
How to Achieve Modularity?
Classes
Modularity Packages
Modules
Minor Elements of OOP
Strong Typing Concurrency Persistence
This means that the type of Concurrency refers to the Persistence refers to the
a variable is known at ability of a program to characteristic of an object
compile time and once a execute multiple parts of a to continue to exist even
variable is declared to be of task simultaneously after the program that
a certain type, it cannot created it has ended
hold values of other types
Object Serialization in Java
• in Java is the process of converting an object's state into a byte stream,
which can then be stored in a file, sent over a network, or transferred
between different Java Virtual Machines
Saved in a File
Serialization
Object Bytes Sent over a Network
From a File
Deserialization
From a Network Bytes Object
From a JVM
How to Serialize and Deserialize?
• Serializable Interface:
• An object can be serialized by implementing the Serializable interface