Professional Documents
Culture Documents
Lecture-2 3
Lecture-2 3
Lecture-2 3
Lecture - 2 & 3
Introduction to Procedural Programming,
DISCOVER . LEARN . EMPOWER
Object-Oriented Programming, Features to
Java
Chapter Course Objectives
2
Contents
• Introduction to Procedurals Oriented Programming Language.
• Introduction to Object Oriented Programming Language.
• Features of OOPs.
• Features of JAVA.
3
Introduction to Procedural Oriented Programming
Language
• Procedural Oriented Programming is a programming language that follows a step-
by-step approach to break down a task into a collection of variables and routines
(or subroutines) through a sequence of instructions. Each step is carried out in
order in a systematic manner so that a computer can understand what to do.
• POP the main program is divided into small parts based on the functions and is
treated as separate program for individual smaller program.
• In OOPs concept of objects and classes is introduced and hence the program is
divided into small chunks called objects which are instances of classes.
5
Differences between POP and OOP
6
Differences between POP and OOP (cont..)
7
Features of Object Oriented Programming
8
What Is an Object?
Note: Hiding internal state and requiring all interaction to be performed through an object's
methods is known as data encapsulation — a fundamental principle of object-oriented
programming.
Benefits of Object
• Modularity: The source code for an object can be written and maintained
independently of the source code for other objects. Once created, an object can be
easily passed around inside the system.
• Information-hiding: By interacting only with an object's methods, the details of
its internal implementation remain hidden from the outside world.
• Code re-use: If an object already exists (perhaps written by another software
developer), you can use that object in your program. This allows specialists to
implement/test/debug complex, task-specific objects, which you can then trust to
run in your own code.
• Pluggability and debugging ease: If a particular object turns out to be
problematic, you can simply remove it from your application and plug in a
different object as its replacement. This is analogous to fixing mechanical
problems in the real world. If a bolt breaks, you replace it, not the entire machine.
What is a Class?
• A class is a blueprint or prototype from which objects are created.
• In the real world, you'll often find many individual objects all of the same kind.
• Ex:
class Bicycle
{
int cadence = 0; int speed = 0; int gear = 1;
void changeCadence(int newValue)
{ cadence = newValue; }
void changeGear(int newValue)
{ gear = newValue; }
void speedUp(int increment)
{ speed = speed + increment; }
}
Ex:- Main method
class BicycleDemo
{
public static void main(String[] args)
{
// Create two different
Bicycle bike1 = new Bicycle();
Bicycle bike2 = new Bicycle();
// Invoke methods on
bike1.changeCadence(50);
bike1.speedUp(10);
bike2.changeCadence(50);
bike2.speedUp(10);
}
}
What Is Inheritance?
• Inheritance provides a powerful and natural mechanism for organizing and
structuring your software.
• When one object acquires all the properties and behaviours of parent
object i.e. known as inheritance.
• It provides code reusability. It is used to achieve runtime polymorphism.
• Ex:
class MountainBike extends Bicycle
{
// new fields and methods defining
// a mountain bike would go here
}
What is a Polymorphism ?
draw() draw()
What is a Abstraction?
17
• Java is a simple programming language.
• This is the design aim of JAVA.
Simple • Omitted Pointer concepts from JAVA.
• Use same syntax of C and C++.
• If a program yields the same result on every machine then that program is
Portability called portable.
• This is the result of Java’s System independence nature.
22
Home Work
Q1. Identify five Difference in-between POPs and OOPs ?
Q2. Illustrate the uses of Object Oriented Programming languages?
23
References
Text Book
• Herbert Schildt (2019), “Java The Complete Reference, Ed. 11, McGraw-Hill .
24
THANK YOU
For queries
Email: kushagra.e13465@cumail.in