SlideShare a Scribd company logo
11
Most read
15
Most read
16
Most read
Software evolution
•Process of continually developing and updating
software to meet the requirements of the
market over time.
•Upgrading the system improves usability and
functionality.
•When the software is upgraded, it is stable
enough to decrease security risks and undergo
cyber attacks over time
Introduction to Procedural Programming
•It can be defined as a programming model which is
derived from structured programming, based upon
the concept of calling procedure.
•Procedures, also known as routines, subroutines or
functions, simply consist of a series of computational
steps to be carried out.
•During a program’s execution, any given procedure
might be called at any point, including by other
procedures or itself.
•Example of procedural programming is C language,
Object-oriented programming
•It can be defined as a programming model which is based
upon the concept of objects.
•Objects contain data in the form of attributes and code in
the form of methods.
• In object-oriented programming, computer programs are
designed using the concept of objects that interact with
the real world.
•Object-oriented programming languages are various but
the most popular ones are class-based, meaning that
objects are instances of classes, which also determine
their types.
Procedural Oriented
Programming
Object-Oriented Programming
In procedural programming, the
program is divided into small parts
called functions.
In object-oriented programming, the
program is divided into small parts
called objects.
Procedural programming follows
a top-down approach.
Object-oriented programming follows
a bottom-up approach.
There is no access specifier in
procedural programming.
Object-oriented programming has
access specifiers like private, public,
protected, etc.
In procedural programming,
overloading is not possible.
Overloading is possible in
object-oriented programming.
In procedural programming, there
is no concept of data hiding and
inheritance.
In object-oriented programming, the
concept of data hiding and inheritance
is used.
Procedural programming is
based on the unreal world.
Object-oriented programming is
based on the real world.
Procedural programming is used
for designing medium-sized
programs.
Object-oriented programming is
used for designing large and
complex programs.
Code reusability absent in
procedural programming,
Code reusability present in
object-oriented programming.
Examples: C, FORTRAN,
Pascal, Basic, etc.
Examples: C++, Java, Python, C#,
etc.
Limitations of procedure oriented
programming
1. Procedural programming mainly focuses on procedures or
functions. Less attention is given to the data.
2. The data and functions are separate from each other.
3. Global data is freely moving and is shared among various functions.
Thus, it becomes difficult for programmers to identify and fix issues
in a program that originate due to incorrect data handling.
4. Changes in data types need to be carried out manually all over the
program and in the functions using the same data type.
5. Limited and difficult code reusability.
6. It does not model real-world entities (e.g., car, table, bank account,
loan) very well where we as a human being, perceive everything as
an object.
7. The procedural programming approach does not work well for
large and complex systems.
Why do we need Object Oriented Programming?
1.Code Organization and Reusability : With OOP, code can be
modularized, promoting reusability and reducing redundancy.
2.Modularity and Scalability : OOP promotes modularity, breaking
down complex systems into smaller, manageable
components. This modular approach also enables scalability,
as new objects can be added or modified without affecting the
entire system.
3.Encapsulation and Data Security: Encapsulation protects data
integrity by allowing controlled access to the internal state of
an object. This enhances data security and reduces the risk of
unintentional data manipulation, as objects control their own
data and expose only necessary interfaces to other objects.
4.Inheritance and Code Reuse: OOP supports inheritance,
where new classes can inherit properties and behaviors
from existing classes. Inheritance facilitates code reuse,
as common functionalities can be defined in a base class
and inherited by derived classes. This reduces code
duplication, improves code organization, and enhances
maintainability.
5.Collaboration and Teamwork: OOP allows multiple
developers to work concurrently on different parts of a
system without conflicts. This promotes teamwork,
simplifies code integration, and streamlines the
development process.
Fundamentals of OOP
• Object Oriented Programming is the most recent concept among programming
model. The motivating factor in the invention of object oriented approach is to
remove some of the flows encountered in the procedural approach.
• Object-Oriented Programming or OOPs refers to languages that use objects in
programming.
• Object-oriented programming aims to implement real-world entities in programming.
• The main aim of OOP is to bind together the data and the functions that operate on
them so that no other part of the code can access this data except that function.
• Some of the striking features of Object Oriented Programming are:
1. Importance on data rather than procedure.
2. Programs are divided into what are known as objects
Characteristics of OOPs are :
•Object
•Classes
•Polymorphism
•Inheritance
•Reusability
•Data abstraction and encapsulation
•Dynamic Binding
•Message Passing
1. Class:
A class is a user-defined data type.
It consists of data members and member functions,
For Example: Consider the Class of Cars. There may be many cars with different names and brands
but all of them will share some common properties like all of them will have 4 wheels. Speed Limit,
Mileage range, etc. So here, Car is the class, and wheels, speed limits, mileage are their properties.
2. Object:
It is a basic unit of Object-Oriented Programming and represents the real-life entities.
An Object is an instance of a Class.
When a class is defined, no memory is allocated but when it is instantiated (i.e. an object is created)
memory is allocated.
An object has an identity, state, and behavior. Each object contains data and code to manipulate the
data.
For example: “Dog” is a real-life Object, which has some characteristics like color, Breed, Bark,
Sleep, and Eats.
Data Abstraction:
Data abstraction refers to providing only essential
information about the data to the outside world, hiding
the background details or implementation.
Consider a real-life example of a man driving a car.
The man only knows that pressing the accelerators will
increase the speed of the car or applying brakes will stop
the car, but he does not know about how on pressing the
accelerator the speed is increasing,
he does not know about the inner mechanism of the car
or the implementation of the accelerator, brakes, etc in
the car. This is what abstraction is.
Encapsulation:
•Encapsulation is defined as the wrapping up of data under a
single unit.
• It is the mechanism that binds together code and the data it
manipulates.
•In Encapsulation, the variables or data of a class are hidden
from any other class and can be accessed only through any
member function of their class in which they are declared.
•As in encapsulation, the data in a class is hidden from other
classes, so it is also known as data-hiding.
Example of Encapsulation
• Consider a real-life example of encapsulation, in a company, there are
different sections like the accounts section, finance section, sales
section, etc.
• The finance section handles all the financial transactions and keeps
records of all the data related to finance.
• Similarly, the sales section handles all the sales-related activities and
keeps records of all the sales.
• Now there may arise a situation when for some reason an official
from the finance section needs all the data about sales in a particular
month.
• In this case,
• he is not allowed to directly access the data of the sales section. He
will first have to contact some other officer in the sales section and
then request him to give the particular data.
• This is what encapsulation is. Here the data of the sales section and
the employees that can manipulate them are wrapped under a single
name “sales section””.
Inheritance
•Inheritance is an important pillar of
OOP(Object-Oriented Programming).
•The capability of a class to derive properties and
characteristics from another class is called Inheritance.
•When we write a class, we inherit properties from other
classes. So when we create a class, we do not need to
write all the properties and functions again and again, as
these can be inherited from another class that possesses
it.
•Inheritance allows the user to reuse the code whenever
possible and reduce its redundancy.
Java Inheritance Example
Programmer is the subclass and Employee is the superclass. The relationship
between the two classes is Programmer IS-A Employee. It means that Programmer is
a type of Employee.
class Employee{
float salary=40000;
}
class Programmer extends Employee{
int bonus=10000;
public static void main(String args[]){
Programmer p=new Programmer();
System.out.println("Programmer salary is:"+p.salary);
System.out.println("Bonus of Programmer is:"+p.bonus);
}
} output= Programmer salary is:40000.0
Bonus of programmer is:10000
Types of Inheritance
Polymorphism
• The word polymorphism means having many forms.
•In simple words, we can define polymorphism as the
ability of a message to be displayed in more than one
form.
For example,
A person at the same time can have different
characteristics. Like a man at the same time is a father, a
husband, an employee. So the same person posses
different behavior in different situations. This is called
polymorphism.
Types of Polymorphism
Dynamic binding
•In dynamic binding, the code to be executed in
response to the function call is decided at runtime.
•Dynamic binding means that the code associated
with a given procedure call is not known until the
time of the call at run time.
•Dynamic Method Binding One of the main
advantages of inheritance is that some derived class
D has all the members of its base class B. Once D is
not hiding any of the public members of B, then an
object of D can represent B in any context where a
B could be used.
•This feature is known as subtype polymorphism.
Example for dynamic binding
class India {
public void locate() {
System.out.println("We are in India");
}
}
class SubIndia extends India {
public void locate() {
System.out.println("We are in Delhi");
}
}
public class DynamicBindingTest {
public static void main(String args[]) {
// Method of super class or parent class is called
India superobj = new India();
superobj.locate();
// Method of sub class or child class is called
by Parent reference,
// this is called "Dynamic Binding"
India subobj = new SubIndia(); // upcasting
subobj.locate();
SubIndia subobj2 = new SubIndia();
subobj2.locate(); // method of sub class or
child class is called
}
}
Output :
We are in India
We are in Delhi
We are in Delhi
Explanation :
In this code, there is a superclass called India that has a method
called locate(), which simply prints "We are in India". The
subclass SubIndia extends India and overrides
the locate() method to print "We are in Delhi".
In the main() method, an object of India is created and
its locate() method is called, which prints "We are in India".
Then, an object of SubIndia is created and upcast to the type
of India. When the locate() method is called on this object using
the India reference variable, dynamic binding comes into play
and the overridden locate() method in the SubIndia class is
called, printing "We are in Delhi". This is because the actual
type of the object is SubIndia, and so its implementation of
the locate() method is used.
Finally, an object of SubIndia is created directly and
its locate() method is called, which again prints "We are in
Delhi".
Message Passing
• It is a form of communication used in object-oriented
programming as well as parallel programming.
• Objects communicate with one another by sending
and receiving information to each other.
• A message for an object is a request for execution of a
procedure and therefore will invoke a function in the
receiving object that generates the desired results.
• Message passing involves specifying the name of the
object, the name of the function, and the information to
be sent.
• For example, when Object A invokes a public method of
Object B, it is sending a message to Object B. Note that
Object A can only invoke Object B's public methods, not
its private methods.

More Related Content

PPTX
Cloud description
DOCX
Plant recognition system
PPTX
Unit - I Intro. to OOP Concepts and Control Structure -OOP and CG (2024 Patte...
PPTX
POP vs OOP Introduction
PPTX
chapterOne.pptxFSdgfqdzwwfagxgghvkjljhcxCZZXvcbx
PPT
Share Unit 1- Basic concept of object-oriented-programming.ppt
PPTX
Ch 1 Introduction to Object Oriented Programming.pptx
PPTX
IET307 OOP - object oriented programming concepts.pptx
Cloud description
Plant recognition system
Unit - I Intro. to OOP Concepts and Control Structure -OOP and CG (2024 Patte...
POP vs OOP Introduction
chapterOne.pptxFSdgfqdzwwfagxgghvkjljhcxCZZXvcbx
Share Unit 1- Basic concept of object-oriented-programming.ppt
Ch 1 Introduction to Object Oriented Programming.pptx
IET307 OOP - object oriented programming concepts.pptx

Similar to UNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPU (20)

PPT
Basic concepts of oops
PPT
Unit 1- Basic concept of object-oriented-programming.ppt
PPTX
Principles of OOPs.pptx
PPTX
Introduction to Object Oriented Programming
PPTX
Unit 2.pptx
PPTX
Unit 2.pptx
PPTX
PPTX
Birasa 1
PPTX
JAVA PROGRAMMING
PDF
L1-Introduction to OOPs concepts.pdf
PPTX
1 unit (oops)
DOC
Chapter1
PPTX
principle of oop’s in cpp
PPTX
JAVA PROGRAMMINGD
PPT
Programming In C++
PPT
Basic Java Concept - Practical Oriented Methodologies
PPTX
CPP-Unit 1.pptx
PPTX
Object Oriented Programming - Cheat sheet.pptx
PPT
Java Fundamentalojhgghjjjjhhgghhjjjjhhj.ppt
PPTX
1 intro
Basic concepts of oops
Unit 1- Basic concept of object-oriented-programming.ppt
Principles of OOPs.pptx
Introduction to Object Oriented Programming
Unit 2.pptx
Unit 2.pptx
Birasa 1
JAVA PROGRAMMING
L1-Introduction to OOPs concepts.pdf
1 unit (oops)
Chapter1
principle of oop’s in cpp
JAVA PROGRAMMINGD
Programming In C++
Basic Java Concept - Practical Oriented Methodologies
CPP-Unit 1.pptx
Object Oriented Programming - Cheat sheet.pptx
Java Fundamentalojhgghjjjjhhgghhjjjjhhj.ppt
1 intro
Ad

Recently uploaded (20)

PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Welding lecture in detail for understanding
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPT
Project quality management in manufacturing
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Geodesy 1.pptx...............................................
PPTX
UNIT 4 Total Quality Management .pptx
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Sustainable Sites - Green Building Construction
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Lecture Notes Electrical Wiring System Components
bas. eng. economics group 4 presentation 1.pptx
CYBER-CRIMES AND SECURITY A guide to understanding
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Welding lecture in detail for understanding
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Operating System & Kernel Study Guide-1 - converted.pdf
Project quality management in manufacturing
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Lesson 3_Tessellation.pptx finite Mathematics
Foundation to blockchain - A guide to Blockchain Tech
Geodesy 1.pptx...............................................
UNIT 4 Total Quality Management .pptx
Arduino robotics embedded978-1-4302-3184-4.pdf
Model Code of Practice - Construction Work - 21102022 .pdf
Sustainable Sites - Green Building Construction
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Internet of Things (IOT) - A guide to understanding
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Ad

UNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPU

  • 1. Software evolution •Process of continually developing and updating software to meet the requirements of the market over time. •Upgrading the system improves usability and functionality. •When the software is upgraded, it is stable enough to decrease security risks and undergo cyber attacks over time
  • 2. Introduction to Procedural Programming •It can be defined as a programming model which is derived from structured programming, based upon the concept of calling procedure. •Procedures, also known as routines, subroutines or functions, simply consist of a series of computational steps to be carried out. •During a program’s execution, any given procedure might be called at any point, including by other procedures or itself. •Example of procedural programming is C language,
  • 3. Object-oriented programming •It can be defined as a programming model which is based upon the concept of objects. •Objects contain data in the form of attributes and code in the form of methods. • In object-oriented programming, computer programs are designed using the concept of objects that interact with the real world. •Object-oriented programming languages are various but the most popular ones are class-based, meaning that objects are instances of classes, which also determine their types.
  • 4. Procedural Oriented Programming Object-Oriented Programming In procedural programming, the program is divided into small parts called functions. In object-oriented programming, the program is divided into small parts called objects. Procedural programming follows a top-down approach. Object-oriented programming follows a bottom-up approach. There is no access specifier in procedural programming. Object-oriented programming has access specifiers like private, public, protected, etc. In procedural programming, overloading is not possible. Overloading is possible in object-oriented programming. In procedural programming, there is no concept of data hiding and inheritance. In object-oriented programming, the concept of data hiding and inheritance is used.
  • 5. Procedural programming is based on the unreal world. Object-oriented programming is based on the real world. Procedural programming is used for designing medium-sized programs. Object-oriented programming is used for designing large and complex programs. Code reusability absent in procedural programming, Code reusability present in object-oriented programming. Examples: C, FORTRAN, Pascal, Basic, etc. Examples: C++, Java, Python, C#, etc.
  • 6. Limitations of procedure oriented programming 1. Procedural programming mainly focuses on procedures or functions. Less attention is given to the data. 2. The data and functions are separate from each other. 3. Global data is freely moving and is shared among various functions. Thus, it becomes difficult for programmers to identify and fix issues in a program that originate due to incorrect data handling. 4. Changes in data types need to be carried out manually all over the program and in the functions using the same data type. 5. Limited and difficult code reusability. 6. It does not model real-world entities (e.g., car, table, bank account, loan) very well where we as a human being, perceive everything as an object. 7. The procedural programming approach does not work well for large and complex systems.
  • 7. Why do we need Object Oriented Programming? 1.Code Organization and Reusability : With OOP, code can be modularized, promoting reusability and reducing redundancy. 2.Modularity and Scalability : OOP promotes modularity, breaking down complex systems into smaller, manageable components. This modular approach also enables scalability, as new objects can be added or modified without affecting the entire system. 3.Encapsulation and Data Security: Encapsulation protects data integrity by allowing controlled access to the internal state of an object. This enhances data security and reduces the risk of unintentional data manipulation, as objects control their own data and expose only necessary interfaces to other objects.
  • 8. 4.Inheritance and Code Reuse: OOP supports inheritance, where new classes can inherit properties and behaviors from existing classes. Inheritance facilitates code reuse, as common functionalities can be defined in a base class and inherited by derived classes. This reduces code duplication, improves code organization, and enhances maintainability. 5.Collaboration and Teamwork: OOP allows multiple developers to work concurrently on different parts of a system without conflicts. This promotes teamwork, simplifies code integration, and streamlines the development process.
  • 9. Fundamentals of OOP • Object Oriented Programming is the most recent concept among programming model. The motivating factor in the invention of object oriented approach is to remove some of the flows encountered in the procedural approach. • Object-Oriented Programming or OOPs refers to languages that use objects in programming. • Object-oriented programming aims to implement real-world entities in programming. • The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function. • Some of the striking features of Object Oriented Programming are: 1. Importance on data rather than procedure. 2. Programs are divided into what are known as objects
  • 10. Characteristics of OOPs are : •Object •Classes •Polymorphism •Inheritance •Reusability •Data abstraction and encapsulation •Dynamic Binding •Message Passing
  • 11. 1. Class: A class is a user-defined data type. It consists of data members and member functions, For Example: Consider the Class of Cars. There may be many cars with different names and brands but all of them will share some common properties like all of them will have 4 wheels. Speed Limit, Mileage range, etc. So here, Car is the class, and wheels, speed limits, mileage are their properties. 2. Object: It is a basic unit of Object-Oriented Programming and represents the real-life entities. An Object is an instance of a Class. When a class is defined, no memory is allocated but when it is instantiated (i.e. an object is created) memory is allocated. An object has an identity, state, and behavior. Each object contains data and code to manipulate the data. For example: “Dog” is a real-life Object, which has some characteristics like color, Breed, Bark, Sleep, and Eats.
  • 12. Data Abstraction: Data abstraction refers to providing only essential information about the data to the outside world, hiding the background details or implementation. Consider a real-life example of a man driving a car. The man only knows that pressing the accelerators will increase the speed of the car or applying brakes will stop the car, but he does not know about how on pressing the accelerator the speed is increasing, he does not know about the inner mechanism of the car or the implementation of the accelerator, brakes, etc in the car. This is what abstraction is.
  • 13. Encapsulation: •Encapsulation is defined as the wrapping up of data under a single unit. • It is the mechanism that binds together code and the data it manipulates. •In Encapsulation, the variables or data of a class are hidden from any other class and can be accessed only through any member function of their class in which they are declared. •As in encapsulation, the data in a class is hidden from other classes, so it is also known as data-hiding.
  • 14. Example of Encapsulation • Consider a real-life example of encapsulation, in a company, there are different sections like the accounts section, finance section, sales section, etc. • The finance section handles all the financial transactions and keeps records of all the data related to finance. • Similarly, the sales section handles all the sales-related activities and keeps records of all the sales. • Now there may arise a situation when for some reason an official from the finance section needs all the data about sales in a particular month. • In this case, • he is not allowed to directly access the data of the sales section. He will first have to contact some other officer in the sales section and then request him to give the particular data. • This is what encapsulation is. Here the data of the sales section and the employees that can manipulate them are wrapped under a single name “sales section””.
  • 15. Inheritance •Inheritance is an important pillar of OOP(Object-Oriented Programming). •The capability of a class to derive properties and characteristics from another class is called Inheritance. •When we write a class, we inherit properties from other classes. So when we create a class, we do not need to write all the properties and functions again and again, as these can be inherited from another class that possesses it. •Inheritance allows the user to reuse the code whenever possible and reduce its redundancy.
  • 16. Java Inheritance Example Programmer is the subclass and Employee is the superclass. The relationship between the two classes is Programmer IS-A Employee. It means that Programmer is a type of Employee. class Employee{ float salary=40000; } class Programmer extends Employee{ int bonus=10000; public static void main(String args[]){ Programmer p=new Programmer(); System.out.println("Programmer salary is:"+p.salary); System.out.println("Bonus of Programmer is:"+p.bonus); } } output= Programmer salary is:40000.0 Bonus of programmer is:10000
  • 18. Polymorphism • The word polymorphism means having many forms. •In simple words, we can define polymorphism as the ability of a message to be displayed in more than one form. For example, A person at the same time can have different characteristics. Like a man at the same time is a father, a husband, an employee. So the same person posses different behavior in different situations. This is called polymorphism.
  • 20. Dynamic binding •In dynamic binding, the code to be executed in response to the function call is decided at runtime. •Dynamic binding means that the code associated with a given procedure call is not known until the time of the call at run time. •Dynamic Method Binding One of the main advantages of inheritance is that some derived class D has all the members of its base class B. Once D is not hiding any of the public members of B, then an object of D can represent B in any context where a B could be used. •This feature is known as subtype polymorphism.
  • 21. Example for dynamic binding class India { public void locate() { System.out.println("We are in India"); } } class SubIndia extends India { public void locate() { System.out.println("We are in Delhi"); } } public class DynamicBindingTest { public static void main(String args[]) {
  • 22. // Method of super class or parent class is called India superobj = new India(); superobj.locate(); // Method of sub class or child class is called by Parent reference, // this is called "Dynamic Binding" India subobj = new SubIndia(); // upcasting subobj.locate(); SubIndia subobj2 = new SubIndia(); subobj2.locate(); // method of sub class or child class is called } }
  • 23. Output : We are in India We are in Delhi We are in Delhi Explanation : In this code, there is a superclass called India that has a method called locate(), which simply prints "We are in India". The subclass SubIndia extends India and overrides the locate() method to print "We are in Delhi". In the main() method, an object of India is created and its locate() method is called, which prints "We are in India". Then, an object of SubIndia is created and upcast to the type of India. When the locate() method is called on this object using the India reference variable, dynamic binding comes into play and the overridden locate() method in the SubIndia class is called, printing "We are in Delhi". This is because the actual type of the object is SubIndia, and so its implementation of the locate() method is used. Finally, an object of SubIndia is created directly and its locate() method is called, which again prints "We are in Delhi".
  • 24. Message Passing • It is a form of communication used in object-oriented programming as well as parallel programming. • Objects communicate with one another by sending and receiving information to each other. • A message for an object is a request for execution of a procedure and therefore will invoke a function in the receiving object that generates the desired results. • Message passing involves specifying the name of the object, the name of the function, and the information to be sent. • For example, when Object A invokes a public method of Object B, it is sending a message to Object B. Note that Object A can only invoke Object B's public methods, not its private methods.