Paradigms of Programming languages:
● Programming paradigm is an approach or a way to solve problems using some
programming languages.
● Programming paradigms are fundamental approaches to writing and organizing
programs.
● Each paradigm provides a different way of thinking about solving problems using a
programming language.
● Programming paradigms are also known as Programming Orientations.
Imperative Programming Paradigm:
● Imperative programming is a programming paradigm that focuses on how to perform
a task by giving step-by-step instructions to the computer to solve a problem.
● The languages C, C++, Java, and Python etc are imperative Programming language.
● Ex:
#include <stdio.h>
int main() {
int sum = 0;
for (int i = 1; i <= 5; i++) {
sum = sum + i;
}
printf("Sum = %d", sum);
return 0;
}
Here we have defined sum as a variable, used a for loop to iterate from 1 to 5.
Each time, we update the state (value of sum) and we print the result at the end.
Declarative Programming Paradigm
● The declarative programming paradigm is a way of programming where we describe
what we want to achieve, not how to achieve it.
● It focuses on expressing logic without explicitly detailing the control flow.
● In other words, instead of giving step-by-step instructions (as in imperative
programming), we declare the desired result and let the language's engine handle the
execution.
● To overcome the problem of explicitly controlling loops in imperative programming,
declarative programming abstracts away the control flow and focuses on what needs
to be done rather than how to do it
● Common Declarative Languages are SQL (Structured Query Language),HTML (Hyper
Text Markup Language) etc
● Ex-1:
SELECT name FROM students WHERE marks > 75;
We simply declare what we want and the SQL engine figures out how to retrieve the
data.
● Ex-2:
<h1>Welcome</h1>
<p>This is a paragraph.</p>
This declares what content to show and the browser decides how to render it.
Procedural Programming paradigm
● Procedural Programming is a subset of Imperative Programming that focuses on the
concept of procedure calls (also known as routines, subroutines, or functions).
● It emphasizes structuring programs into procedures to improve modularity,
readability, and reusability.
● The languages C, Pascal, Python etc are procedural Programming language.
● Ex:
#include <stdio.h>
// Procedure to add two numbers
int add(int a, int b) {
return a + b;
}
// Main procedure
int main() {
int x = 10, y = 20, result;
result = add(x, y); // Call the add procedure
printf("Sum = %d\n", result);
return 0;
}
Functional Programming Paradigm:
● Functional Programming (FP) is a programming paradigm where programs are
constructed by applying and composing functions.
● It treats computation as the evaluation of mathematical functions and avoids
changing state and mutable data.
● Ex:
List<Integer> numbers = [Link](1, 2, 3, 4, 5, 6);
int result = [Link]()
.filter(n -> n % 2 == 0) // Keep even numbers
.map(n -> n * n) // Square each number
.reduce(0, Integer::sum); // Sum all squares
[Link]("Sum of squares of even numbers: " + result);
Object Oriented Programming Paradigm:
● Object-Oriented Programming (OOP) is a programming paradigm that solves
problems by modeling them using real-world entities as objects.
● It uses key features such as classes, objects, methods, inheritance, encapsulation,
abstraction, and polymorphism to organize and manage code effectively.
● Ex:
class Student {
String name;
int age;
void display() {
[Link](name + " is " + age + " years old.");
}
}
public class Main {
public static void main(String[] args) {
Student s1 = new Student();
[Link] = "John";
[Link] = 20;
[Link]();
}
}
Basic Concepts of OOPs:
● OPPs stands for Object Oriented Programming
● It is one of the Programming Paradigm
● The below are the basic components of Object Oriented Programming
1. Class
2. Object
3. Method
4. Data Hiding
5. Data Abstraction
6. Encapsulation
7. Inheritance
8. Method Overloading
9. Method Overriding
10.Polymorphism
11.Message Passing
Class:
● Class is a blue print or plan or design that contains complete information to
represent real world entities.
● We can write a class to represent properties (attributes) and actions (behavior) of
object.
● Properties can be represented by variables
● Actions can be represented by Methods.
● Hence class contains both variables and methods.
● Class is a user defined data type that represents data and related functions.
● Class is a virtual encapsulation of properties and behavior.
● Ex: Student class can have properties of student like roll no, name, group and
behavior like read and write as below
class Student{
int rollno = 1;
String name = “anil”;
String group = “BSC;
public void read(){
[Link](“I am reading”);
}
public void write(){
[Link](“I am writing”);
}
}
Object:
● A physical existence of a class is called as Object
● Without creation of Objects, there is no use of developing classes.
● Object is an individual element among the group of elements having same physical
properties and physical behavior.
● Object is physical encapsulation of properties and behavior.
● Ex:
rahul, ram and rani are objects of class Student.
Student rahul = new Student();
Student ram = new Student();
Student rani = new Student();
● For any class, multiple objects can be created.
● Reference Variable:
● The variables which can be used to refer objects is called as reference variable
● By using reference variable we can operate objects, i.e by using reference variables
we can access the variables and methods.
● There can be one to many relation between object and reference variables i.e. we
can create any number of reference variables to the same object.
Method:
● Method is a small block that represents specific functionality.
● In OOPs, methods can be used to represent behaviour of the Real entities.
● Methods look like functions.
● Ex-1:
public void walk(){
//body of the method
}
public void talk(){
//body of the method
}
Data Hiding:
● Data Hiding means hiding of data
● The process of protecting internal data from unauthorized access is Data Hiding.
● It means, outside person or program cannot access our internal data directly.
● We can achieve data hiding by declaring the data members as private
● The advantage of data hiding is to provide security to the data.
Data Abstraction:
● The process of hiding internal implementation and just highlighting the set of
services what we are offering, is called as Data Abstraction.
● The main advantage of Data Abstraction is to provide security,
● It improves the easiness to use our system.
Encapsulation:
● The process of binding data and corresponding methods into a single unit, is called as
encapsulation.
● It any component follows Data hiding and Abstraction, such type of component is
said to be encapsulated component.
● Ex:
class Student{
data variables + methods
}
● The main advantage of Encapsulation is to achieve data security.
Inheritance:
● The process of getting variables and methods from one class into another class is
called as Inheritance
● The class from which data and methods are getting inherited, is called as Base class
or super class or Parent class.
● The class into which the data and methods are getting inherited is called as child
class or sub class.
● Ex:
class Parent {
void m1() {
[Link]("Parent class method");
}
}
class Child extends Parent {
void m2() {
[Link]("Child class method");
}
}
Method Overloading:
● The feature which allows to have same name for multiple methods but different
argument types is called as method overloading.
● The main objective of the overloading is to reduce the complexity of the
programming.
● Ex:
// Method with 2 int parameters
public int add(int a, int b) {
return a + b;
}
// Method with 3 int parameters
public int add(int a, int b, int c) {
return a + b + c;
}
Method Overriding:
● Method Overriding is a feature in object-oriented programming that allows a
subclass (child class) to provide a specific implementation of a method that is already
defined in its superclass (parent class).
● It improves code reusability.
● Ex:
class Parent {
void m1() {
[Link]("Parent class method");
}
}
class Child extends Parent {
@Override
void m1() {
[Link]("Child class method");
}
}
Polymorphism:
● Polymorphism is a Greek word, where poly means many and morphism means
forms.
● It is the ability to take more than one form with a single name.
● We can implement Polymorphism using method overloading and method overriding.
● The main advantage of Polymorphism is flexibility to design applications.
Message Passing:
● The process of transferring data along with flow of execution from one object to
another object, called as Message Passing.
● The message passing involves the following basic steps
1. Creating classes that define objects
2. Creating objects from class definition
3. Establishing communication among objects
● The main advantage of message passing is to improve communication between the
objects and data navigation between the entities.
Differences between Procedure Oriented Programming and Object Oriented Programming:
POP OOP
POP stands for Procedural Oriented OOP stands for Object Oriented
Programming Programming
In POP, program is divided into small parts In OOP, program is divided into small
called as Functions parts called objects and classes.
In POP, data is shared and can be accessed In OOP, Data is kept private inside objects
by any function. and accessed via method.
POP does not have any access specifier OOP has access specifiers named public,
private, protected and default.
POP follows top-down approach OOP follows bottom-up approach
In POP, code reusability happens through In OOP, code reusability happens via
functions. classes and objects (inheritance)
POP provides less security for data OOP provides more security for data
Overloading, Overriding and Encapsulation Overloading, Overriding and Encapsulation
are not possible in POPs are possible in OOPs
Ex: C, PASCAL, FORTRAN etc. Ex: C++, Java, R, Python etc.
Explain benefits of OOPs:
● OOPs stands for Object Oriented Programming.
● It is one of the programming paradigm.
● It mainly works on Object Oriented features such as Class, Object, Method, Data
Hiding, Data Abstraction, Encapsulation, Overloading, Overriding, Polymorphism etc.
● The below are the key benefits of OOPs:
1. In OOP, we can create programs by reusing existing classes and objects, which
saves time and increases productivity, instead of writing all the code from
scratch.
2. OOPs allows to break large programs into smaller, self-contained modules
(classes), making code easier to manage and understand.
3. OOPs allows to hide sensitive data from outside world and only accessible
through methods.
4. OOPs supports code reusability by eliminating duplication of code through
Inheritance.
5. OOP systems are easy to upgrade from small to large because new features can
be added using new classes without changing existing code. This improves
scalability and maintainability.
6. It is possible that multiple instances of objects co-exist without any interference.
7. OOPs allow to have same method names with different behaviours in different
classes through polymorphism.
8. Easier to maintain and scale because of clear modular structure and reusability.
9. OOPs supports Message Passing which promotes Encapsulation.
Applications of OOPs:
● Object-Oriented Programming (OOP) is widely used in software development
because it models real-world entities as "objects." .
● This makes complex programs easier to design, maintain, and extend.
● Below are key applications of Object Oriented Programming.
1. Real Time Systems:
OOP is ideal for real time systems like traffic control, simulation systems or
robotics where objects can represent sensors, devices etc.
2. Web Applications:
OOP is used in web applications like online shopping, booking systems, and
content management where objects represent users, products, and orders.
3. Gamming Applications:
In games, characters, enemies, and environments are objects with specific
behaviours and attributes. OOP allows reusability and modular design.
4. GUI Applications (Graphical User Interface):
OOP is used in GUI frameworks (like Java Swing, JavaFX) to represent windows,
buttons, and forms as objects.
5. Mobile Applications:
Android applications are fully OOP-based. Classes like Activity, View, and Intent
are object-oriented.
6. Banking and Financial Systems:
OOP is used to model real-world banking operations such as accounts, customers, and
transactions.
7. Healthcare Systems:
OOP is useful in designing hospital management systems where patients, doctors, and
appointments are modelled as objects.
8. Education systems:
OOP is used in LMS (Learning Management Systems) where Students, Teachers,
Course and Tests are represented as objects.