Introduction To Object Oriented Programming: by Megha V Gupta, NHITM
Introduction To Object Oriented Programming: by Megha V Gupta, NHITM
Introduction To Object Oriented Programming: by Megha V Gupta, NHITM
Introduction to
Object Oriented
Programming
3
Object oriented programming
Object oriented programming (OOP) is a concept
that combines both the data and the functions that
operate on that data into a single unit called the
object.
An object is a collection of set of data known as
member data and the functions that operate on these
data known as member function.
OOP follows bottom-up design technique.
Class is the major concept that plays important role
in this approach. Class is a template that represents a
group of objects which share common properties
and relationships. 4
Differences
Procedural Programming Object Oriented Programming
Large programs are divided into Programs are divided into
smaller programs known as objects
functions
5
History of Java
■ Java was originally designed for interactive television, but it was too advanced
technology for the digital cable television industry at the time.
■ Java team members (also known as Green Team), initiated this project to
develop a language for digital devices such as set-top boxes, televisions, etc.
■ However, it was suited for internet programming. Later, Java technology was
incorporated by Netscape.
■ The principles for creating Java programming were "Simple, Robust, Portable,
Platform-independent, Secured, High Performance, Multithreaded, Architecture
Neutral, Object-Oriented, Interpreted, and Dynamic".
■ Java was developed by James Gosling, who is known as the father of Java, in
1995. James Gosling and his team members started the project in the early
'90s.
■ James Gosling - founder of java
■ Currently, Java is used in internet programming, mobile devices, games, e-
business solutions, etc. There are given significant points that describe the
history of Java.
■ Java is an island of Indonesia where the first coffee was produced
(called java coffee). It is a kind of espresso bean. Java name was
chosen by James Gosling while having coffee near his office.
■ Notice that Java is just a name, not an acronym.
Features of Java
Platform Independent and
secured
OOP
■ Object-Oriented Programming is a methodology
or paradigm to design a program using classes and
objects. It simplifies software development and
maintenance by providing some concepts:
• Object
• Class
• Inheritance
• Polymorphism
• Abstraction
• Encapsulation
OOP Concepts
1
5
Objects
Objects are basic building blocks for designing
programs.
An object is a collection of data members and
associated member functions.
An object may represent a person, place or a table
of data.
Each object is identified by
a unique name. Each object must
be a member of a particular class.
Example: Apple, orange, mango
are the objects of class fruit.
1
6
Objects
■ 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.
■ 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.
q
Encapsulation
Data Encapsulation:
◦ The wrapping of data and functions into a single unit
(class) is called data encapsulation.
◦ Data encapsulation enables data hiding and information
hiding.
Data hiding:
It is a method used in object oriented programming to
hide information within computer code.
Abstraction
Abstraction refers to the quality of dealing with ideas
rather than events. It basically deals with hiding the
details and showing the essential things to the user. If
you look at the image here, whenever we get a call,
we get an option to either pick it up or just reject it.
But in reality, there is a lot of code that runs in the
background. So you don’t know the internal
processing of how a call is generated, that’s the
beauty of abstraction. Therefore, abstraction helps to
reduce complexity. You can achieve abstraction in
two ways:
a) Abstract Class
b) Interface
Encapsulation
■ The best way to understand encapsulation is to look at the
example of a medical capsule, where the drug is always
safe inside the capsule. Similarly, through encapsulation
the methods and variables of a class are well hidden and
safe.
10
Principles of OOPs
▸Polymorphism
If one task is performed by different ways, it
is known as polymorphism.