0% found this document useful (0 votes)
27 views

OOP in Java Unit1

Java note

Uploaded by

free98072fire
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

OOP in Java Unit1

Java note

Uploaded by

free98072fire
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

By: Manoj Sapkota, Nepal Polytechnic Institute

Unit-1: Object-Oriented Programming

Procedural Oriented Programming (POP): It is a programming model that is


based on the concept of calling procedures. The procedures consist of a
sequence of statements or the computational steps to be executed. These
procedures are the blocks in which the set of instructions to be executed by the
computer are organized. These procedures are also known as routines, sub-
routines or functions.

Some of the key features of this POP are as follows:


• Modular Structure: Programs are divided into smaller, manageable units
called procedures or functions. Each function performs a specific task.
• Sequential Execution: Functions are executed in a predefined order.
Control structures such as loops and conditionals are used to manage
the flow of execution.
• Global Data and Local Data: Data is often shared globally, meaning it
can be accessed by any function in the program. Functions can also have
local variables that are only accessible within the function.
• Function Calls: Functions are called to perform specific operations, often
taking input parameters and returning results.
• Top-Down Design: Development typically follows a top-down approach,
starting with the overall structure and breaking it down into smaller,
more detailed parts.
• Examples of POP Languages: Common languages that support
procedural programming include C, Fortran, and Pascal.

A typical program structure for procedural programming is shown in figure


below.

Figure: Procedural programming language

1
By: Manoj Sapkota, Nepal Polytechnic Institute

Object Oriented Programming: It is a programming approach that is based on


the concept of objects. In this approach, a problem is decomposed into a
number of entities which are known as objects. The data and functions are
then built around these objects. The organization of data and functions in the
object-oriented programming are shown in the figure below:

Figure: Object Oriented Programming

Principles/Features of Object-Oriented Programming:


Some of the key features of Object-Oriented Programming language are:
1. Object: In OOP, the problem is decomposed into a number of small units
which are known as objects. These objects are the real-world entities.
Example of object could be any entity such as particular book, a student,
an employee, etc.
2. Class: It is a collection of objects. It is regarded as a template or
blueprint of the objects. It is a user-defined data type that holds various
variables and functions under one construct. Example of a class could be
a template that represents a collection of books in a library, or a number
of students at a college, or number of employees in an organization.
3. Encapsulation and data hiding: The wrapping of data and functions
into a single unit is known as encapsulation. The data are kept private
and are not accessible to the outside world. These data are accessed by
only the member functions that are present in the same unit (i.e., in the
same class). This process is also known as data hiding as the data are
hidden from outside.
4. Abstraction: It refers to the process of displaying only the essential
features without including the background details. It helps to increase
the security of the system.

2
By: Manoj Sapkota, Nepal Polytechnic Institute

5. Inheritance: It is a feature in which one object can inherit the properties


of another. With the help of inheritance, the redundant codes are
eliminated and the use of existing classes can be extended.
6. Polymorphism: It is a feature in which the same function or operator
can be used to perform differently in different situations.

Advantages of OOP:
• The modeling of real-world problems become easy by using OOP as it
represents all the real-world entities as objects.
• By the use of inheritance, the redundant codes are eliminated and the
existing features can be extended.
• It supports encapsulation, i.e., the data and functions are wrapped
inside a single unit. The data is protected from the outside and only the
associated functions can access them. So, it provides more security to
the system.
• With the help of polymorphism, the same function or operator can be
used for various purposes. This helps to manage the complexity of the
software with ease.
• Large problems can be reduced to smaller and manageable ones. It is
easy to partition the work in a project based on objects.
• Object oriented system can be easily upgraded from small to a large
system.
• Software complexity can be easily managed.
• It supports abstraction so that the internal implementation can be
modified without affecting the user. It helps to increase the security of
the system.

Disadvantages of OOP:
• It has a steep learning curve and can be complex for beginners.
• It can lead to performance overhead.
• Code written in OOP tends to be larger.
• It might be inefficient for simple and straightforward problems.
• Integrating OOP with relational databases can be problematic.
• Overuse of inheritance can lead to tightly coupled systems.

3
By: Manoj Sapkota, Nepal Polytechnic Institute

Differences between OOP and Procedural Oriented Programming (POP):


POP OOP
1. It is the old programming concept 1. It is the most recent programming
that uses the top-down approach. concept that uses the bottom-up
approach.
2. Programs are divided into a 2. Programs are divided into a
number of smaller program number of entities known as objects.
segments called functions.
3. Emphasis is on procedures 3. Emphasis is on data rather than
rather than on data. on procedures.
4. It is less secure as there is no 4. It is more secure as it has data
data hiding feature. hiding feature.
5. Data and functions don’t tie with 5. Data and functions tie with each
each other. other.
6. It allows the data to move freely 6. Data is hidden and so cannot be
around the program from one accessed by external functions due to
function to another. encapsulation.
7. It can solve moderately complex 7. It can solve any complex programs.
programs.
8. Problem is not viewed as a real 8. Problem is viewed as a real-world
word entity. entity.
9. It does not support inheritance 9. It supports inheritance and
and polymorphism. polymorphism.
10. Example languages: C, Pascal, 10. Example languages: C++, Java,
FORTRAN and C#

MODEL/IMPORTANT QUESTIONS:
1. What is object-oriented approach? What are the advantages of OOP
over procedural oriented programming? Explain.
2. What are the features/principles of OOP? Explain.
3. What are the differences between Object Oriented Programming
(OOP) and Procedural oriented programming? Explain.

You might also like