Professional Documents
Culture Documents
INTRODUCTION
TO
OBJECT-ORIENTED PROGRAMMING
(OOP)
Objects
Members
4/6/2024
Contents
1. Overview of OOP
2. Java, JVM and Byte Code
3. Basic Concepts of OOP
Classes
Objects
Members
4/6/2024
Overview of OOP
Object-oriented programming (OOP) is a
programming paradigm that uses “Objects “and
their interactions to design applications.
OOP focuses on the objects that developers want to
manipulate rather than the logic required to
manipulate them.
Thisapproach to programming is well-suited for
programs that are large, complex and actively
updated or maintained.
The first step in OOP is to collect all of the objects
a programmer wants to manipulate and identify
how they relate to each other (Data Modeling).
Examples of an object can range from physical entities,
such as a human being who is described by properties
like name and address, down to small computer
programs, such as Widgets.
Once an object is known, it is labeled with
a class of objects that defines the kind of data it
contains and any logic sequences that can
manipulate it.
Each distinct logic sequence is known as a method.
Objects can communicate with well-defined
interfaces called messages.
Basic principles of OOP
Basic principles of OOP
OOP contains the following fundamentals principles
Abstraction
◼ Allows us to consider complex ideas while ignoring
irrelevant detail that would confuse us.
◼ It is the process of selecting data from a larger pool to show
only the relevant details to the object.
◼ This concept helps developers more easily make changes
and additions over time.
◼ Example
◼ Suppose you want to create a dating application and you are
asked to collect all the information about your users.
Example: Abstraction
Dating application
Full name, address, phone number, favorite
food, favorite movie, hobbies, tax information,
social security number, credit score
Identifying an Object?
You can also think of other non physical things as objects:-
such as a bank account
◼ A bank account is not something that can be physically touched
but intellectually we can consider a bank account to be an object.
OOP is a method of programming that involves the
creation of intellectuals objects that model a business
problem we are trying to solve.
In creating an OO program we define the properties of a
class of objects and then create individual objects from the
class
4/6/2024
Benefits of OOP Approach
15
Better abstraction
Modeling information and behavior together
Better maintainability
More comprehensible, less fragile software
Better usability
Classes as encapsulated components that can be used
in other systems
4/6/2024
Contents
1. Overview of OOP
2. Java, JVM and Byte Code
3. Basic Concepts of OOP
Classes
Objects
Members
4/6/2024
Java, JVM and Byte code
17
Java
Java is a programming language and a platform.
Java is a high level, robust, object-oriented and secure
programming language.
Java was developed by Sun Microsystems (which is now
the subsidiary of Oracle) in the year 1995.
James Gosling is known as the father of Java.
4/6/2024
18
4/6/2024
19
Object Oriented
In Java, everything is an Object. Java can be easily
extended since it is based on the Object model.
Simple
Java is designed to be easy to learn. If you understand the
basic concept of OOP Java, it would be easy to master.
Secure
With Java's secure feature it enables to develop virus-free,
tamper-free systems. Authentication techniques are based
on public-key encryption.
4/6/2024
22
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 the
Virtual Machine (JVM) on whichever platform it is being run on.
Robust
Java makes an effort to eliminate error-prone situations by
emphasizing mainly on compile time error checking and
runtime checking.
4/6/2024
23
Portable
Beingarchitecture-neutral and having no
implementation dependent aspects of the specification
makes Java portable.
◼ The compiler in Java is written in ANSI C with a clean
portability boundary, which is a POSIX subset.
Architecture-neutral
Java compiler generates an architecture-neutral object
file format, which makes the compiled code executable
on many processors, with the presence of Java runtime
system.
4/6/2024
24
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 an extensive amount of run-time
information that can be used to verify and resolve accesses to
objects at run-time.
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 light-weight process.
4/6/2024
25
High Performance
With the use of Just-In-Time compilers, Java enables high
performance.
Multithreaded
With Java's multithreaded feature it is possible to write
programs that can perform many tasks simultaneously.
◼ This design feature allows the developers to construct interactive
applications that can run smoothly.
Distributed
Java is designed for the distributed environment of the
internet.
4/6/2024
Java Virtual Machine(JVM)
26
4/6/2024
27
What is JVM?
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.
4/6/2024
28
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
4/6/2024
Java bytcode
29
4/6/2024
30 4/6/2024
Contents
1. Overview of OOP
2. Java, JVM and Byte Code
3. Basic Concepts of OOP
Objects
Classes
Members
4/6/2024
Basic Concepts of OOP
32
What is Object?
Object: A single software unit that combines
attributes and methods. It represents an entity in
the real world.
Attribute:A "characteristic" of an object; like a
variable associated with a kind of object.
Method: A "behavior" of an object; like a function
associated with a kind of object.
4/6/2024
33
Example
Dog
◼ Attributes:breed, color, hungry, tired, etc.
◼ Behaviors: eating, sleeping, etc.
Bank Account
◼ Attributes:account number, owner, balance
◼ Behaviors: withdraw, deposit
4/6/2024
What is Classes?
34
4/6/2024
Bank Example
class: Account
The "account" class describes the
number:
attributes and behaviors of
balance:
bank accounts.
deposit()
The “account” class defines two
withdraw()
state variables (account number
and balance) and two methods
(deposit and withdraw).
Bank Example – three objects
Instance #1
number: 054
When the program runs there
balance: $19
will be many instances of the
Instance #2
account class.
number: 712
Each instance will have its own
balance: $240
account number and balance Instance #3
4/6/2024
Members of the class
39
4/6/2024
40
4/6/2024
Class Members Visibility
41
4/6/2024
42
Questions?
4/6/2024
43
Thank You
4/6/2024