OOP Lecture-1
OOP Lecture-1
Instructor: Kebebe.S(Msc)
March, 2021 Fitche
Ethiopia
Outline
Types of programming paradigm .
Overview of OO principles.
Java Program.
1
Imperative
Assumes that the computer can maintain through
environments of variables any changes in a
computation process.
Computations are performed through a guided
sequence of steps, in which these variables are
referred to or changed.
The order of the steps is crucial, because a given
step will have different consequences depending on
the current values of variables when the step is
executed.
“First do this and next do that”
2
Cont’d
There are two reasons for popularity:
the imperative paradigm most closely resembles the
actual machine itself, so the programmer is much
closer to the machine.
because of such closeness, the imperative paradigm
was the only one efficient enough for widespread
use until recently.
Language representatives
Example: Fortran, Algol, Pascal, Basic, C
3
Cont’d
There are two reasons for popularity:
The imperative paradigm most closely resembles
the actual machine itself, so the programmer is
much closer to the machine.
Because of such closeness, the imperative
paradigm was the only one efficient enough for
widespread use until recently.
Language representatives
Example: Fortran, Algol, Pascal, Basic, C
4
Cont’d
Advantages Disadvantages
efficient; The semantics of a
close to the machine; program can be complex
popular;
to understand or prove;
Debugging is harder;
familiar.
Abstraction is more
limited than with some
paradigms;
Order is crucial, which
doesn't always suit itself
to problems.
5
Logical
Takes a declarative approach to problem-solving.
logical deduction.
6
Cont’d
Logical Paradigm Programming:
❑ A logical program is divided into three sections:
▪ a series of definitions/declarations that define the
problem domain
▪ statements of relevant facts
▪ statement of goals in the form of a query
❑ Any deducible solution to a query is returned.
7
Cont’d
The definitions and declarations are constructed entirely
8
Functional
Views all subprograms as functions in the mathematical
9
Object-Oriented
Is a paradigm in which real-world objects are each
viewed as separate entities having their own state which
is modified only by built in procedures, called methods.
Because objects operate independently, they are
encapsulated into modules which contain both local
environments and methods.
Communication with an object is done by message
passing.
Objects are organized into classes, from which they
inherit methods and equivalent variables.
The object-oriented paradigm provides key benefits of
reusable code and code extensibility.
10
Features & Benefits
Data as well as operations are encapsulated in objects.
Information hiding is used to protect internal properties of
an object.
Inheritance gives OOP its chief benefit over other
programming paradigms - relatively easy code reuse and
extension without the need to change existing source
code.
The derived class can also override behavior
corresponding to some of the methods of the base class:
there would be a different method to respond to the same
message.
11
Overview of OO principles
In order for a programming language to be object-
12
Cont’d
Inheritance
It allows a class to "inherit" (behavior or characteristics)
of another, more general class.
For example, a lion belongs to the biological family of cats
(Felidae). All cats that have four paws, are predators and
hunt their prey.
This functionality can be coded once in the Felidae class
and all its predators can reuse it
– Tiger, Puma, Bobcat, etc.
Inheritance is described as a kind-of relationship, e.g.
Tiger is kind of Animal.
13
Cont’d
Abstraction
Means working with something we know how to use
without knowing how it works internally.
A good example is a television set. We don’t need to
know the inner workings of a TV, in order to use it.
All we need is a remote control with a small set of buttons
(the interface of the remote) and we will be able to
watch TV.
14
Cont’d
Polymorphism
15
Overview of Java Programming
Java programming language was originally developed by
Sun Microsystems which was initiated by James Gosling and
released in 1995 as core component of Sun Microsystems‘
Java platform (Java 1.0 [J2SE]).
The latest release of the Java Standard Edition is Java SE 8.
With the advancement of Java and its widespread
popularity, multiple configurations were built to suit various
types of platforms. For example: J2EE for Enterprise
Applications, J2ME for Mobile Applications.
The new J2 versions were renamed as Java SE, Java EE,
and Java ME respectively. Java is guaranteed to be Write
Once, Run Anywhere.
16
Overview of Java Programming(Cont’d)
Java is -
Object Oriented - In Java, everything is an Object. Java can
be easily extended since it is based on the Object model.
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.
17
Overview of Java Programming(Cont’d)
Java is –
❑ 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.
❑ 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.
18
Overview of Java Programming (Cont’d)
❑ Portable - Being architecture-neutral and having no implementation
dependent aspects of the specification makes Java portable.
❑ 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 perform many tasks simultaneously.
❑ Interpreted - Java byte code is translated on the fly to native
machine instructions and is not stored anywhere.
❑ 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.
19
Types of Java Program
❑ Java Applet - These are small programs written in java
and is usually stored on a website and is downloaded
and run on a client computer from within a web browser.
❑ Application - can only be run on the computer. If online,
it has to be downloaded before being run.
❑ Servlet - runs on a web server and helps to display web
pages.
❑ Swing application - is used to build an application that
has a GUI (windows, buttons, menus, etc.)
❑ EJB - runs on a web server and is used to develop large,
complex websites.
20
Definition of Java Application, Java Applets
❑ Application is a Java class that has a main() method.
❑ An applet is a Java class which extends java.applet.Applet.
❑ Application is a stand-alone program, normally launched
from the command line, and which has unrestricted access to
the host system.
❑ An applet is a program which is run in the context of an
applet viewer or web browser, and which has strictly limited
access to the host system.
❑ For instance, an applet can normally not read or write files
on the host system whereas an application normally can.
❑ Applets may communicate with other applets running on the
same virtual machine.
21
Editing, Compiling and Interpreting
Editing
All you need to write and edit Java code is a text editor,
such as the "NotePad" editor that we have used to this
point.
Each file must be saved under the name classname.java
Compiling
Before you can do anything with your Java code, you have
to compile it; "compiling" refers to the process by which
high-level, human-readable Java code is turned into a long
string of bytes (much like a machine language) which can
be understood by a Java interpreter.
22
Cont.d
Interpreting
"Interpreted" means that the computer looks at the
language, and then turns it into native machine language.
he term Java interpreter refers to a program which
implements the JVM specification and actually executes
the bytecodes by running your program.
Compiler versus Interpreter
Compiling happens when the writing of the program is
finished like calling javac. Example: – JAVAC
Your_class_name.java
Interpretation happens at runtime(which means while
running the Java program), Example: – JAVA
Your_class_name
23
26