Procedural vs object-oriented programming (often written POP vs OOP) is about how you organise code. In procedural programming, the program is a set of functions, and data is kept separately and passed between them. In object-oriented programming, data and the functions that work on it live together inside objects. Both styles produce working programs. The difference shows up as programs grow.
POP vs OOP: the comparison table
| Point | Procedural (POP) | Object-oriented (OOP) |
|---|---|---|
| Basic unit | Function (procedure) | Object, made from a class |
| Focus | Steps: what to do, in order | Things: what objects exist and what they can do |
| Data and functions | Separate | Bundled together |
| Data protection | Little; data is often global or passed freely | Encapsulation with private, public and methods |
| Reuse | Call the same function again | Inheritance and composition |
| Same name, different behaviour | Not built in | Polymorphism (overriding, overloading) |
| Approach | Top-down: break the task into smaller functions | Bottom-up: model objects, then connect them |
| Typical languages | C, Pascal, Fortran, early BASIC | Java, C#, Kotlin; C++ and Python support both |
| Best for | Small programs, scripts, system code, algorithms | Large applications with many related parts |
One program written both ways
Task: two bank accounts. Deposit into one, try to withdraw too much from the other, and print the balances. Both versions are in Java so you can see that the style, not the language, makes the difference.
Procedural version
public class BankProcedural {
// Data lives in plain variables, separate from the functions
static String[] names = {"Ravi", "Sita"};
static double[] balances = {5000, 3000};
static void deposit(int index, double amount) {
balances[index] = balances[index] + amount;
}
static boolean withdraw(int index, double amount) {
if (amount > balances[index]) {
return false;
}
balances[index] = balances[index] - amount;
return true;
}
public static void main(String[] args) {
deposit(0, 1500);
boolean ok = withdraw(1, 4000);
System.out.println(names[0] + ": " + balances[0]);
System.out.println(names[1] + ": " + balances[1] + " (withdraw ok? " + ok + ")");
balances[1] = -999; // nothing stops this
System.out.println(names[1] + ": " + balances[1]);
}
}
Output:
Ravi: 6500.0
Sita: 3000.0 (withdraw ok? false)
Sita: -999.0
It works, and for a tiny program it is easy to read. But look at the last two lines of main. Any code can write any value into balances, skipping the rule in withdraw. And the name and balance of one person sit in two different arrays, linked only by the same index.
Object-oriented version
class Account {
private final String name;
private double balance; // hidden: only the methods below can change it
Account(String name, double balance) {
this.name = name;
this.balance = balance;
}
void deposit(double amount) {
balance = balance + amount;
}
boolean withdraw(double amount) {
if (amount > balance) {
return false;
}
balance = balance - amount;
return true;
}
@Override
public String toString() {
return name + ": " + balance;
}
}
public class BankOop {
public static void main(String[] args) {
Account ravi = new Account("Ravi", 5000);
Account sita = new Account("Sita", 3000);
ravi.deposit(1500);
boolean ok = sita.withdraw(4000);
System.out.println(ravi);
System.out.println(sita + " (withdraw ok? " + ok + ")");
}
}
Output:
Ravi: 6500.0
Sita: 3000.0 (withdraw ok? false)
Now each Account holds its own name and balance. If code in BankOop tries sita.balance = -999;, the compiler refuses:
error: balance has private access in Account
sita.balance = -999;
^
The only way to change a balance is through deposit and withdraw, which enforce the rules. This is encapsulation, and it is the biggest practical gain of OOP.
What changes when the program grows
Say the bank now needs a savings account that earns interest and a current account that allows an overdraft.
In procedural code, you add more arrays (types, overdraftLimits) and fill withdraw with if checks on the account type. Every new account type means editing the same functions again, and every function must remember the rules.
In OOP, you create SavingsAccount and CurrentAccount classes that extend Account. CurrentAccount overrides withdraw to allow the overdraft. Code that calls account.withdraw(...) does not change at all; the right version runs for each object. That is inheritance plus polymorphism.
Why OOP is considered better, and when it is not
Where OOP helps
- Safer data: rules live next to the data they protect.
- Easier teamwork: one developer can work on
Accountwhile another works onLoan. - Reuse: shared behaviour goes into a parent class.
- Matches real projects: Java frameworks like Spring Boot are built around classes and objects.
Where procedural code is fine or better
- short scripts and one-off tasks
- algorithm problems in coding rounds, where a few functions are clearest
- low-level system code in C, such as drivers and embedded programs
- performance-critical loops where extra objects add overhead
Common mistake: Making a class for everything, even a two-line calculation, because "OOP is better". Over-designed code with many tiny classes is harder to read than a simple function. Use classes when there is real data with rules to protect.
Many modern languages, including Python, Kotlin and modern Java, mix styles. Java 8 added lambdas and streams from functional programming. Good developers pick the style that fits the problem.
Exam answer: difference between POP and OOP
If your university exam asks for the differences, these six points cover most marking schemes:
- POP divides a program into functions; OOP divides it into objects.
- POP follows a top-down approach; OOP follows a bottom-up approach.
- POP has no access specifiers; OOP has
private,protectedandpublic. - In POP, data moves freely between functions; in OOP, data is hidden inside objects.
- POP has no inheritance or polymorphism; OOP supports both.
- Examples: C, Pascal, Fortran for POP; Java, C#, C++ for OOP.
Where to go next
Learn the four pillars properly in our OOP concepts in Java lesson, and see the private plus methods pattern in detail in encapsulation. If your syllabus starts with C, read C vs Java to see how the two languages differ beyond style. Then practise with OOPs interview questions and Java OOP interview questions.
Interview note: Do not just list textbook points. Say: "In procedural code, data and functions are separate, so any function can change the data. In OOP, the class keeps the data private and exposes methods, so rules like 'no withdrawal above balance' are always enforced." Then give the bank account example in two sentences.
Frequently Asked Questions
Is C procedural or object-oriented?
Is Python procedural or object-oriented?
Is OOP always better than procedural programming?
What are the four pillars of OOP?
Can Java be written in a procedural style?
Want to Build Your Career in Java Full Stack with AI?
Join CodeBegun and train with working industry engineers — See the Java Full Stack course in Hyderabad

