Object Oriented Programming (OOP) : Chapter One
Object Oriented Programming (OOP) : Chapter One
CHAPTER ONE
10/02/2022 1
Computer:- is a device that can perform computations
and make logical decisions phenomenally faster than
human beings can.
It is electronic device for storing and processing data,
typically in binary form, according to instructions given to
it in a variable program
10/02/2022 2
computer
Hardware Software
Using programing
Using semiconductor device languages
10/02/2022 3
Programming Language
A program:- is a description of a set of actions that we want a
computer to carry out.
A programming language:- is an artificial language used to
write instructions that can be translated into machine
language and then executed by a computer.
10/02/2022 7
• Since the computer cannot understand .code
assembly language, however, a program mov ax,@data
called assembler is used to convert assembly mov ds,ax
language programs into machine code. mov ax,opr1
mov bx,opr2
clc
• For example, to add two numbers, you might add ax,bx
write an instruction in assembly code like mov di,offset result
this. mov [di], ax
.model small mov ah,09h
mov dx,offset result
.data
int 21h
opr1 dw 1234h mov ah,4ch
opr2 dw 0002h int 21h
result dw 01 dup(?),
10/02/2022
end 8
High-Level Language
• The high-level languages are English-like and easy to learn
and program.
• For example, the following is a high-level language
statement that computes the area of a circle with radius 5:
area = 5 * 5 * 3.1415;
10/02/2022 9
Popular High-Level Languages
COBOL (COmmon Business Oriented Language)
FORTRAN (FORmula TRANslation)
BASIC (Beginner All-purpose Symbolic Instructional
Code)
Pascal (named for Blaise Pascal)
Ada (named for Ada Lovelace)
C (whose developer designed B first)
10/02/2022 10
Popular High-Level Languages…
Visual Basic (Basic-like visual language developed
by Microsoft)
Delphi (Pascal-like visual language developed by
Borland)
C++ (an object-oriented language, based on C)
C# (a Java-like language developed by Microsoft)
Java (object-oriented language ,We will learn in
this course)
10/02/2022 11
Programming languages are used to solve problems
using computers in various domains such as:
Scientific Applications
Business Applications
Artificial Intelligence
Systems Programming
Web Applications
10/02/2022 12
Scientific Applications
The first digital computers, which appeared in the 1940s, were used and
in fact invented for scientific applications.
Typically, scientific applications have relatively simple data structures but
require large numbers of floating-point arithmetic computations.
The most common data structures are arrays and matrices
The most common control structures are counting loops and selections
The first language for scientific applications was Fortran (FORmula
TRANslation), created by Corrado Böhm in 1951, for his PhD thesis
Others (e.g., Cobol, Lisp, Ada) are too specialized to adapt
for scientific use.
Matlab is widely used in university settings
10/02/2022 13
Business Applications
Special computers were developed for business application
purpose, along with special languages.
Business languages are characterized by facilities for
Producing elaborate reports
Precise ways of describing and storing decimal
numbers and character data
The ability to specify decimal arithmetic
operations
Example: COBOL …
Java….JavaScript. ...C# ...C+
+ ...Python. ...PHP. ...Ruby .
10/02/2022 14
Artificial Intelligence
10/02/2022 15
Systems Programming
The operating system and all of the programming
support tools of a computer system are
collectively known as its systems software.
Systems software is used almost continuously and
so it must be efficient.
Assembly language and C language are mostly
used in this area.
10/02/2022 16
Web Applications
A web application or "web app" is a software program that
runs on a web server and accessed through a web browser.
Web app languages:
Java
Phyton
PHP
JavaScript
Ruby
……
10/02/2022 17
What Are the Top Programming Languages?
• According to IEEE Spectrum's interactive ranking, Python is
the top programming language of 2017, followed by C, Java
and C++.
• Of course, the choice of which language to use depends on
the type of computer the program is to run on, what sort of
program it is, and the expertise of the programmer.
10/02/2022 18
IEEE Spectrum Interactive Ranking (2017)
10/02/2022 19
Programming paradigm
• A programming paradigm is a fundamental style of computer
programming.
• Programming paradigms differ in:
• the concepts and abstractions used to represent the elements of
a program (such as objects, functions, variables, constraints,
etc.)
• the steps that compose a computation (assignation, evaluation,
data flow, control flow, etc.).
10/02/2022 20
Cont..
• Some languages are designed to support one particular paradigm
• Smalltalk supports object-oriented programming
• Haskell supports functional programming
• Other programming languages support multiple paradigms
• Object Pascal, C++, C#, Visual Basic, Common Lisp, Scheme,
Perl, Python, Ruby, Oz and F#.
• The design goal of multi-paradigm languages is to allow
programmers to use the best tool for a job, admitting that no one
paradigm solves all problems in the easiest or most efficient way.
10/02/2022 21
Programing paradigm
»Imperative/procedural : Machine-model based
WHAT DO WE DO NEXT ?
»Functional : Equations; Expression Evaluation
WHAT IS THE FUNCTION’S VALUE ?
»Logical : First-order Logic Deduction
WHEN IS IT TRUE THAT … ?
»Object-Oriented : Programming with Data Types
WHAT ARE THE TERMS OF THE CONTRACT ?
10/02/2022 22
Procedural Programming
• This programming paradigm is essentially an
abstraction of machine /assembly language.
• Program is organized around procedures.
• Focus on data structures, algorithms and sequencing
of steps
• Operations are executed one after another in
sequence.
10/02/2022 23
Procedural Programming…
• An algorithm is a set of instructions for solving a
problem
• A data structure is a construct used to organize data
in a specific way.
• Most computer languages, from early examples like
FORTRAN and ALGOL to more recent languages like
C and Ada, have been imperative or procedural.
10/02/2022 24
Functional Programming
• It treats computation as the evaluation of mathematical
functions and avoids state and mutable data.
• Functional programming is all about expressions.
• Functions are used as objects in FP.
• Functional Programming is about abstraction and reducing
complexity.
• program as a collection of (math) functions
• E.g. LISP, ML, Haskell
10/02/2022 25
Logic Programming
• It is the use of mathematical logic for computer
programming.
• The problem-solving task is split between the programmer
and theorem- prover.
• To study logic programming means to study proofs.
• It is based upon the fact of a backwards reasoning proof
• Prolog is a general purpose logic programming language
associated with artificial intelligence and computational
linguistics
• It is based on Facts and Rules
10/02/2022 26
Object Oriented Paradigm
• Object-oriented programming (OOP) is a programming
paradigm that uses "objects" – data structures consisting of
datafields and methods together with their interactions – to
design applications and computer programs.
10/02/2022 27
Object oriented programming
• Object-Oriented Programming is a
methodology or paradigm to design a
program using classes and objects.
10/02/2022 28
Compilation and Interpretation
Different ways of executing a program
compilation
interpretation
Compilation and interpretation are properties of the implementation of a
language
What exactly is compilation?
In a compiled implementation of a language, a compiler will translate the program directly into code that is specific to
the target machine, which is also known as machine code
Then the computer will run the machine code on its own.
What exactly is interpretation?
In an interpreted implementation of a language, the source code is not directly run by the target machine.
What happens instead is that another program reads and then executes the original source code.
This other program is also known as the interpreter.
The interpreter is usually written specifically for the native machine.
an interpreter that converts the intermediate code into machine specific code.
10/02/2022 29
The compilation process
Preprocessing:
• Removing comments
• Syntax checking
• Parsing: break up a sentence/group of
word
Compiling: generates assembly language,
an intermediate human readable language,
specific to the target processor.
• Assembly: The assembler will convert the
assembly code into pure binary code or
machine code (0 and 1). This code is also
known as object code.
• Linking: The linker merges all the object
code from multiple modules into a single one.
10/02/2022 30
Runtime environment
• A software program needs to execute, and to do that it needs an
environment to run in.
• Runtime environment is a state of the target machine, which may include
software libraries, environment variables, etc., to provide services to the
processes running in the system.
• By runtime, we mean a program in execution.
• The runtime environment loads class files and ensures there is access to
memory and other system resources to run them.
• When it was first introduced, Java's "write once, run anywhere (WORA"
principle was considered revolutionary, but today it's been adopted as a
norm for most software systems.
10/02/2022 31
Java Runtime Environment(JRE)
• The JRE is a software layer that runs on top of a computer's operating
system, providing additional services specific to Java.
• JRE contains the Java class libraries, the Java class loader, and the Java
Virtual Machine. In this system:
• The class loader is responsible for correctly loading classes and connecting them
with the core Java class libraries.
• The JVM is responsible for ensuring Java applications have the resources they
need to run and perform well in your device or cloud environment and ensures
dependencies are available to your Java programs
• The JRE is mainly a container for those other components, and is responsible for
orchestrating their activities.
• The JRE smoothes over the diversity of operating systems, ensuring that
Java programs can run on virtually any OS without modification.
10/02/2022 32
A layered architectural view shows that the JRE contains the
JVM, class loader, and Java class libraries
10/02/2022 33
Integrated Development Environment (IDE)
• Java IDE is a software application that enables users to write and debug Java
programs more easily.
• Most IDEs have features such as syntax highlighting and code completion that helps
users to code more easily.
• Usually, Java IDEs include a code editor, a compiler, a debugger, and an
interpreter that the developer may access via a single graphical user interface.
• The following are the best Java IDEs that are mostly used in the world:
• NetBeans
• Eclipse
• NetBeans
• IntelliJ IDEA…..
10/02/2022 34
Overview of OO principles
Object
Class
Inheritance
Polymorphism
Abstraction
Encapsulation
10/02/2022 35
Object
10/02/2022 36
Class…
• A class is a definition of objects of the same
kind.
• In other words, a class is a blueprint,
template, or prototype that defines and
describes the static attributes and dynamic
behaviors common to all objects of the same
kind.
• E.g. mango, apple and orange are members of
the class fruit.
10/02/2022 37
Inheritance
• Inheritance : a way of organizing classes
• Term comes from inheritance of traits like
eye color, hair color, and so on.
• Classes with properties in common can be
grouped so that their common properties
are only defined once.
• Is an “is a kind of” relationship
10/02/2022 38
Inheritance…
• The mechanism of deriving a new class
from an old class is called inheritance
or derivation.
• The old class is known as base class (super
class) while new class is known as derive
class or sub class.
10/02/2022 39
Polymorphism
Polymorphism is a Greek term which means ability
to take more than one form.
• For example, + is used to make sum of two numbers
as well as it is used to combine two strings.
• This is known as operator overloading because same
operator may behave differently on different
instances.
• Same way functions can be overloaded.
For example, sum () function may takes two argume
nts or three arguments etc. i.e
sum (5, 7) or sum (4, 6, 8).
10/02/2022 40
Polymorphism…
Analogy:
• In English, bank can mean side of a river or a
place to put money
• In Java, two or more classes could each have a
method called output
• Each output method would do the right
thing for the class that it was in.
• One output might display a number whereas
a different one might display a name.
10/02/2022 41
Abstraction
• Refers to the act of representing important
description without including the background
details or explanations.
Abstraction:
Emphasizes relevant characteristics.
Suppresses other characteristics
Data abstraction
is a programming (and design) technique that r
elies on the separation of interface
and implementation. Example: phone call, we
10/02/2022don't know the internal processing. 42
Encapsulation
• Encapsulation means to design, produce, and
describe software so that it can be easily used
without knowing the details of how it works.
Also known as information hiding
• “Encapsulation is a process of binding data
members (variables, properties) and member
functions (methods) into a single unit”.
10/02/2022 43
Encapsulation…
Analogy:
√When you drive a car, you don’t have
know the details of how many cylinders
the engine has or how the gasoline and
air are mixed and ignited.
√Instead you only have to know how to use
the controls.
10/02/2022 44
Procedural Vs Object-Oriented
• Emphasis on data
procedural
abstraction.
abstraction.
• Bottom-up
Top-down design;
design;
Step-wiselibraries.
Reusable refinement.
• Suited for programming in the large.
small.
10/02/2022 45
Q
End of
chapter
one
10/02/2022 46