Dr. A. Haja Abdul Khader
Assistant Professor of Computer Science
11-08-2020
1
What is OOP
Object-oriented programming System(OOPs) is
a programming paradigm based on the
concept of “objects” that contain data and
methods.
The primary purpose of object-oriented
programming is to increase the flexibility and
maintainability of programs
Object oriented programming brings together
data and its behaviour(methods) in a single
location(object) makes it easier to understand
how a program works.
11-08-2020
2
Difference Between POP and OOP
11-08-2020
3
Procedural Oriented Programming Object Oriented Programming
In procedural programming, program is
divided into small parts called functions.
In object oriented programming,
program is divided into small parts
called objects.
Procedural programming follows top
down approach.
Object oriented programming follows
bottom up approach.
There is no access specifier in
procedural programming.
Object oriented programming have
access specifiers like private, public,
protected etc.
Adding new data and function is not
easy.
Adding new data and function is easy.
Difference Between POP and OOP
11-08-2020
4
Procedural Oriented Programming Object Oriented Programming
Procedural programming does not
have any proper way for hiding data
so it is less secure.
Object oriented programming
provides data hiding so it is more
secure.
In procedural programming,
overloading is not possible.
Overloading is possible in object
oriented programming.
In procedural programming, function
is more important than data.
In object oriented programming, data
is more important than function.
Difference Between POP and OOP
11-08-2020
5
Procedural Oriented Programming Object Oriented Programming
Procedural programming is based on
unreal world.
Object oriented programming is
based on real world.
Examples: C, FORTRAN, Pascal, Basic
etc.
Examples: C++, Java, Python, C# etc.
Advantages of OOP
1) OOPs makes development and maintenance
easier, whereas, in a procedure-oriented
programming language, it is not easy to
manage if code grows as project size increases.
2) OOPs provides data hiding, whereas, in a
procedure-oriented programming language,
global data can be accessed from anywhere.
11-08-2020
6
Advantages of OOP
3) OOPs provides the ability to simulate real-
world event much more effectively. We can
provide the solution of real word problem if we
are using the Object-Oriented Programming
language.
11-08-2020
7
What is an Object
 Any entity that has state and behavior is known
as an object. For example, a chair, pen, table,
keyboard, bike, etc. It can be physical or
logical.
An Object can be defined as an instance of a
class. An object contains an address and takes
up some space in memory.
11-08-2020
8
What is an Object
 Objects can communicate without knowing the
details of each other's data or code.
 The only necessary thing is the type of message
accepted and the type of response returned by
the objects.
Example: A dog is an object because it has
states like color, name, breed, etc. as well as
behaviors like wagging the tail, barking, eating,
etc.
11-08-2020
9
What is an Object
11-08-2020
10
What is Class
 A collection of objects is called a class.
It is a logical entity.
A class can also be defined as a blueprint from
which you can create an individual object.
Class doesn't consume any space
11-08-2020
11
OOP Concepts in Java
There are four main OOP concepts in Java.
These are:
Abstraction
Encapsulation
Inheritance
Polymorphism
11-08-2020
12
Abstraction
Hiding internal details and showing functionality
is known as abstraction.
Abstraction means using simple things to
represent complexity.
We all know how to turn the TV on, but we don’t
need to know how it works in order to enjoy it.
11-08-2020
13
Abstraction
In Java, abstraction means simple things like
objects, classes, and variables represent more
complex underlying code and data.
This is important because it lets avoid repeating
the same work multiple times.
11-08-2020
14
How Abstraction Works
Abstraction as an OOP concept in Java works
by letting programmers create useful, reusable
tools.
For example, a programmer can create several
different types of objects. These can be
variables, functions, or data structures.
Programmers can also create different classes
of objects. These are ways to define the objects.
11-08-2020
15
Encapsulation
Binding (or wrapping) code and data together
into a single unit are known as encapsulation.
 For example, a capsule, it is wrapped with
different medicines.
11-08-2020
16
Encapsulation
This is the practice of keeping fields within a
class private, then providing access to them via
public methods.
It’s a protective barrier that keeps the data and
code safe within the class itself.
 This way, we can re-use objects like code
components or variables without allowing open
access to the data system-wide.
11-08-2020
17
How Encapsulation Works
This is the practice of keeping fields within a
class private, then providing access to them via
public methods.
It’s a protective barrier that keeps the data and
code safe within the class itself.
 This way, we can re-use objects like code
components or variables without allowing open
access to the data system-wide.
11-08-2020
18
How Encapsulation Works
Encapsulation lets us re-use functionality without
jeopardizing security.
It’s a powerful OOP concept in Java because it
helps us save a lot of time.
 For example, we may create a piece of code
that calls specific data from a database.
11-08-2020
19
How Encapsulation Works
It may be useful to reuse that code with other
databases or processes.
Encapsulation lets us do that while keeping our
original data private.
It also lets us alter our original code without
breaking it for others who have adopted it in the
meantime.
11-08-2020
20
Inheritance
The process by which one class acquires the
properties and functionalities of another class is
called inheritance.
Inheritance provides the idea of reusability of
code and each sub class defines only those
features that are unique to it, rest of the features
can be inherited from the parent class.
11-08-2020
21
Inheritance
The process by which one class acquires the
properties and functionalities of another class is
called inheritance.
Inheritance provides the idea of reusability of
code and each sub class defines only those
features that are unique to it, rest of the features
can be inherited from the parent class.
11-08-2020
22
Inheritance
Inheritance is a process of defining a new class
based on an existing class by extending its
common data members and methods.
Inheritance allows us to reuse of code, it
improves reusability in your java application.
The parent class is called the base class or super
class. The child class that extends the base class
is called the derived class or sub class or child
class.
11-08-2020
23
How Inheritance Works
Inheritance is another labor-saving Java OOP
concept.
 It works by letting a new class adopt the
properties of another.
We call the inheriting class a subclass or a child
class.
The original class is often called the parent.
 We use the keyword extends to define a new
class that inherits properties from an old class.
11-08-2020
24
Polymorphism
If one task is performed in different ways, it is
known as polymorphism.
For example: to convince the customer
differently, to draw something, for example,
shape, triangle, rectangle, etc.
There are two kinds of polymorphism:
1. Static (Compile-time)
2. Dynamic( Run-time)
11-08-2020
25
Polymorphism
This Java OOP concept lets programmers use
the same word to mean different things in
different contexts.
 One form of polymorphism in Java is method
overloading
That’s when different meanings are implied by
the code itself. The other form is method
overriding.
That’s when the different meanings are implied
by the values of the supplied variables. 11-08-2020
26
How Polymorphism Works
Polymorphism in Java works by using a
reference to a parent class to affect an object
in the child class.
 We might create a class called “horse” by
extending the “animal” class. That class might
also implement the “professional racing” class.
The “horse” class is “polymorphic,” since it
inherits attributes of both the “animal” and
“professional racing” class.
11-08-2020
27
How Polymorphism Works
11-08-2020
28

Ah java-ppt2

  • 1.
    Dr. A. HajaAbdul Khader Assistant Professor of Computer Science 11-08-2020 1
  • 2.
    What is OOP Object-orientedprogramming System(OOPs) is a programming paradigm based on the concept of “objects” that contain data and methods. The primary purpose of object-oriented programming is to increase the flexibility and maintainability of programs Object oriented programming brings together data and its behaviour(methods) in a single location(object) makes it easier to understand how a program works. 11-08-2020 2
  • 3.
    Difference Between POPand OOP 11-08-2020 3 Procedural Oriented Programming Object Oriented Programming In procedural programming, program is divided into small parts called functions. In object oriented programming, program is divided into small parts called objects. Procedural programming follows top down approach. Object oriented programming follows bottom up approach. There is no access specifier in procedural programming. Object oriented programming have access specifiers like private, public, protected etc. Adding new data and function is not easy. Adding new data and function is easy.
  • 4.
    Difference Between POPand OOP 11-08-2020 4 Procedural Oriented Programming Object Oriented Programming Procedural programming does not have any proper way for hiding data so it is less secure. Object oriented programming provides data hiding so it is more secure. In procedural programming, overloading is not possible. Overloading is possible in object oriented programming. In procedural programming, function is more important than data. In object oriented programming, data is more important than function.
  • 5.
    Difference Between POPand OOP 11-08-2020 5 Procedural Oriented Programming Object Oriented Programming Procedural programming is based on unreal world. Object oriented programming is based on real world. Examples: C, FORTRAN, Pascal, Basic etc. Examples: C++, Java, Python, C# etc.
  • 6.
    Advantages of OOP 1)OOPs makes development and maintenance easier, whereas, in a procedure-oriented programming language, it is not easy to manage if code grows as project size increases. 2) OOPs provides data hiding, whereas, in a procedure-oriented programming language, global data can be accessed from anywhere. 11-08-2020 6
  • 7.
    Advantages of OOP 3)OOPs provides the ability to simulate real- world event much more effectively. We can provide the solution of real word problem if we are using the Object-Oriented Programming language. 11-08-2020 7
  • 8.
    What is anObject  Any entity that has state and behavior is known as an object. For example, a chair, pen, table, keyboard, bike, etc. It can be physical or logical. An Object can be defined as an instance of a class. An object contains an address and takes up some space in memory. 11-08-2020 8
  • 9.
    What is anObject  Objects can communicate without knowing the details of each other's data or code.  The only necessary thing is the type of message accepted and the type of response returned by the objects. Example: A dog is an object because it has states like color, name, breed, etc. as well as behaviors like wagging the tail, barking, eating, etc. 11-08-2020 9
  • 10.
    What is anObject 11-08-2020 10
  • 11.
    What is Class A collection of objects is called a class. It is a logical entity. A class can also be defined as a blueprint from which you can create an individual object. Class doesn't consume any space 11-08-2020 11
  • 12.
    OOP Concepts inJava There are four main OOP concepts in Java. These are: Abstraction Encapsulation Inheritance Polymorphism 11-08-2020 12
  • 13.
    Abstraction Hiding internal detailsand showing functionality is known as abstraction. Abstraction means using simple things to represent complexity. We all know how to turn the TV on, but we don’t need to know how it works in order to enjoy it. 11-08-2020 13
  • 14.
    Abstraction In Java, abstractionmeans simple things like objects, classes, and variables represent more complex underlying code and data. This is important because it lets avoid repeating the same work multiple times. 11-08-2020 14
  • 15.
    How Abstraction Works Abstractionas an OOP concept in Java works by letting programmers create useful, reusable tools. For example, a programmer can create several different types of objects. These can be variables, functions, or data structures. Programmers can also create different classes of objects. These are ways to define the objects. 11-08-2020 15
  • 16.
    Encapsulation Binding (or wrapping)code and data together into a single unit are known as encapsulation.  For example, a capsule, it is wrapped with different medicines. 11-08-2020 16
  • 17.
    Encapsulation This is thepractice of keeping fields within a class private, then providing access to them via public methods. It’s a protective barrier that keeps the data and code safe within the class itself.  This way, we can re-use objects like code components or variables without allowing open access to the data system-wide. 11-08-2020 17
  • 18.
    How Encapsulation Works Thisis the practice of keeping fields within a class private, then providing access to them via public methods. It’s a protective barrier that keeps the data and code safe within the class itself.  This way, we can re-use objects like code components or variables without allowing open access to the data system-wide. 11-08-2020 18
  • 19.
    How Encapsulation Works Encapsulationlets us re-use functionality without jeopardizing security. It’s a powerful OOP concept in Java because it helps us save a lot of time.  For example, we may create a piece of code that calls specific data from a database. 11-08-2020 19
  • 20.
    How Encapsulation Works Itmay be useful to reuse that code with other databases or processes. Encapsulation lets us do that while keeping our original data private. It also lets us alter our original code without breaking it for others who have adopted it in the meantime. 11-08-2020 20
  • 21.
    Inheritance The process bywhich one class acquires the properties and functionalities of another class is called inheritance. Inheritance provides the idea of reusability of code and each sub class defines only those features that are unique to it, rest of the features can be inherited from the parent class. 11-08-2020 21
  • 22.
    Inheritance The process bywhich one class acquires the properties and functionalities of another class is called inheritance. Inheritance provides the idea of reusability of code and each sub class defines only those features that are unique to it, rest of the features can be inherited from the parent class. 11-08-2020 22
  • 23.
    Inheritance Inheritance is aprocess of defining a new class based on an existing class by extending its common data members and methods. Inheritance allows us to reuse of code, it improves reusability in your java application. The parent class is called the base class or super class. The child class that extends the base class is called the derived class or sub class or child class. 11-08-2020 23
  • 24.
    How Inheritance Works Inheritanceis another labor-saving Java OOP concept.  It works by letting a new class adopt the properties of another. We call the inheriting class a subclass or a child class. The original class is often called the parent.  We use the keyword extends to define a new class that inherits properties from an old class. 11-08-2020 24
  • 25.
    Polymorphism If one taskis performed in different ways, it is known as polymorphism. For example: to convince the customer differently, to draw something, for example, shape, triangle, rectangle, etc. There are two kinds of polymorphism: 1. Static (Compile-time) 2. Dynamic( Run-time) 11-08-2020 25
  • 26.
    Polymorphism This Java OOPconcept lets programmers use the same word to mean different things in different contexts.  One form of polymorphism in Java is method overloading That’s when different meanings are implied by the code itself. The other form is method overriding. That’s when the different meanings are implied by the values of the supplied variables. 11-08-2020 26
  • 27.
    How Polymorphism Works Polymorphismin Java works by using a reference to a parent class to affect an object in the child class.  We might create a class called “horse” by extending the “animal” class. That class might also implement the “professional racing” class. The “horse” class is “polymorphic,” since it inherits attributes of both the “animal” and “professional racing” class. 11-08-2020 27
  • 28.