0% found this document useful (0 votes)
17 views29 pages

Chapter 1 - Introduction To Object-Oriented Programming

Uploaded by

jacobdiriba
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
17 views29 pages

Chapter 1 - Introduction To Object-Oriented Programming

Uploaded by

jacobdiriba
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 29

Programming Paradigm

- Ermias N.
8, July 2021
Paradigm can also be termed as method to solve some problem or
do some task.

Programming paradigm is an approach to solve problem using some


programming language using tools and techniques that are available
to us following some approach.

There are lots for programming language that are known but all of
them need to follow some strategy when they are implemented and
this methodology/strategy is paradigms.
Cont’d…

Major Programming Paradigms

Imperative programming Declarative programming


paradigm paradigm

•Procedural •Object Logic Database


Functional
programming oriented programming Processing
Programming
paradigm programming paradigm Approach
Imperative Programming Paradigm:

• It works by changing the program state through assignment


statements.

• “How" to accomplish a task is a concern here.


• It is based on Von Neumann architecture.
• Compile to binary executable that run more efficiently since
all CPU instructions are themselves imperative statements.
Cont’d…
Advantage:
• Very simple to implement
• It contains loops, variables etc.

Disadvantage:
• Complex problem cannot be solved
• Less efficient and less productive
Cont’d…

Imperative programming is divided into two broad


categories:
• Procedural,
• OOP
Procedural programming paradigm
• Is intuitive in the sense that it is very similar to how you would
expect a program to work.
• It uses a list of instructions to tell the computer what to do step-
by-step.
• Procedural programming relies procedures, also known as
routines or subroutines.
Object oriented programming
• The program is written as a collection of classes and object
which are meant for communication.
• The smallest and basic entity is object and all kind of
computation is performed on the objects only.
• More emphasis is on data rather procedure.
• With this object technology we can handle almost all kind of real
life problems which are today in scenario.
B-b-b-but,….
What is object technology then?
Cont’d…
…let’s begin with a simple analogy.
Suppose you want to drive a car and make it go faster by pressing
its accelerator pedal.
What must happen before you can do this?

Someone has to design it!


Including that accelerator pedal; The thing that hides
complex mechanisms from the driver that actually make
the car go faster.
Cont’d…

….just as the brake pedal hides the mechanisms that


slow the car, and the steering wheel “hides” the
mechanisms that turn the car.
But, you cannot drive a car’s engineering drawings 
right?
It must be built with the actual accelerator pedal to
make it go faster
And, that’s not enough –the driver must press the
pedal
Methods and Classes
• The method houses the program statements that actually
perform its tasks.
• The method hides these statements from its user, just as the
accelerator pedal of a car hides from the driver the
mechanisms of making the car go faster. (The pedal!)
• In OPP, a program construct called class is used to house the
set of methods that perform the class’s tasks. (The car’s
engineering drawing)
Instantiation

• Just as someone has to build a car from its engineering


drawings before you can actually drive a car, you must build
an object of a class before a program can perform the tasks
that the class’s methods define.
• An object is then referred to as an instance of its
class.(Everyone's car)
Reuse

• Just as a car’s engineering drawings can be reused many


times to build many cars, you can reuse a class many times
to build many objects.
• Reuse of existing classes when building new classes and
programs saves time and effort.
…As existing classes and components often have undergone
extensive testing, debugging and performance tuning.
Messages and Method Calls

• When you drive a car, pressing its gas pedal sends a message to the
car to perform a task— that is, to go faster.
• Similarly, you send messages to an object.
• Each message is implemented as a method call that tells a method of
the object to perform its task.
Attribute and Instance variables

• A car, besides having capabilities to accomplish tasks, also has


attributes, such as its color, its number of doors, the amount of gas in
its tank, its current speed and its record of total miles driven (i.e., its
odometer reading).
• Like its capabilities, the car’s attributes are represented as part of its
design in its engineering diagrams (which, for example, include an
odometer and a fuel gauge).
• An object, similarly, has attributes that it carries along as it’s used in a
program. These attributes are specified as part of the object’s class.
Encapsulation and Information Hiding

• You can know how much gas is in your own gas tank, but not
how much is in the tanks of other cars.
• Objects may communicate with one another, but they’re
normally not allowed to know how other objects are
implemented
—implementation details are hidden within the
objects themselves.
Java and a Typical Java Development Environment

• Microprocessors are having a profound impact in intelligent


consumer-electronic devices.
• 1991
• Recognizing this, Sun Microsystems funded an internal corporate
research project led by James Gosling, which resulted in a C++-
based object-oriented programming language; Sun called it Java.
• Key goal of Java is to be able to write programs that will run on a
great variety of computer systems and computer-control devices.
• This is sometimes called “write once, run anywhere.” (WORA)
Cont’d…

• Sun Microsystems was acquired by Oracle in 2009.


• As of 2021, there are more than 3 billion java-enabled devices around
the word.
• Java is the most widely used software development language in the
world.
Cont’d…

And also has well written Libraries


• Rich collections of existing classes and methods
• Also known as the Java APIs (Application Programming Interfaces).
Cont’d…

Editing, Compiling and Executing

Phase 1 consists of editing a file


• Type a Java program (source code) using the editor.
• Make any necessary corrections.
• Save the program.
• A file name ending with the .java extension indicates that the file
contains Java source code.
Cont’d…

Phase 2: Compiling a Java Program into Bytecodes


• Use the command javac (the Java compiler) to compile a program.
For example, to compile a program called Welcome.java, you need
to type
• javac Welcome.java
• If the program compiles, the compiler produces a .class file called
Welcome.class that contains the compiled version of the program.

©1992-2012 by Pearson Education, Inc. All Rights Reserved.


Cont’d…

• Java compiler translates Java source code into bytecodes that


represent the tasks to execute.
• Bytecodes are executed by the Java Virtual Machine (JVM)—a part of
the JDK and the foundation of the Java platform.
• Virtual machine (VM)—a software application that simulates a
computer
• Hides the underlying operating system and hardware from the programs that
interact with it.
• If the same VM is implemented on many computer platforms,
applications that it executes can be used on all those platforms.
Cont’d…

• Bytecodes are platform independent


• They do not depend on a particular hardware platform.
• Bytecodes are portable
• The same bytecodes can execute on any platform containing a JVM that
understands the version of Java in which the bytecodes were compiled.
• The JVM is invoked by the java command. For example, to execute a
Java application called Welcome, you’d type the command
• java Welcome
Cont’d…

Phase 3: Loading a Program into Memory


• The JVM places the program in memory to execute it—this is
known as loading.
• Class loader takes the .class files containing the program’s
bytecodes and transfers them to primary memory.
• Also loads any of the .class files provided by Java that your program
uses.
• The .class files can be loaded from a disk on your system or
over a network.
Cont’d…

Phase 4: Bytecode Verification


• As the classes are loaded, the bytecode verifier examines their
bytecodes
• Ensures that they’re valid and do not violate Java’s security
restrictions.
• Java enforces strong security to make sure that Java programs
arriving over the network do not damage your files or your
system (as computer viruses and worms might).
Cont’d…

Phase 5: Execution
• The JVM executes the program’s bytecodes.
• JVMs typically execute bytecodes using a combination of
interpretation and so-called just-in-time (JIT) compilation.
• Analyzes the bytecodes as they’re interpreted
• A just-in-time (JIT) compiler—known as the Java HotSpot compiler—
translates the bytecodes into the underlying computer’s machine
language.
Cont’d…

• When the JVM encounters these compiled parts again, the faster
machine-language code executes.
• Java programs go through two compilation phases
• One in which source code is translated into bytecodes (for
portability across JVMs on different computer platforms) and
• A second in which, during execution, the bytecodes are translated
into machine language for the actual computer on which the
program executes.
QUIZ:

What is object Instantiation?

You might also like