Languages Comparisonbeginner

Procedural vs Object-Oriented Programming

Procedural code is a list of functions working on shared data; OOP bundles data and its functions into objects. See one program written both ways and compare.

5 min read

Our verdict in 30 seconds

Procedural programming (POP) organises a program as a sequence of functions that work on data kept separately, as in C. Object-oriented programming (OOP) groups data and the functions that use it into objects made from classes, as in Java, and adds encapsulation, inheritance and polymorphism. POP is simple and direct for small programs; OOP scales better for large programs that many people maintain.

On This Page

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 Account while another works on Loan.
  • 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:

  1. POP divides a program into functions; OOP divides it into objects.
  2. POP follows a top-down approach; OOP follows a bottom-up approach.
  3. POP has no access specifiers; OOP has private, protected and public.
  4. In POP, data moves freely between functions; in OOP, data is hidden inside objects.
  5. POP has no inheritance or polymorphism; OOP supports both.
  6. 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?
C is procedural. It has functions and structs but no classes, no inheritance and no access control like private. C++ added classes on top of C, so it supports both styles.
Is Python procedural or object-oriented?
Python supports both. Everything in Python is an object, but you can write a whole script with just functions. Many beginners write procedural Python first and add classes later.
Is OOP always better than procedural programming?
No. For a small script, a math routine or a short coding-round solution, plain functions are often clearer. OOP pays off when the program is large, has many related types of data and is changed by a team over time.
What are the four pillars of OOP?
Encapsulation (hide data behind methods), abstraction (show only what is needed), inheritance (reuse a parent class) and polymorphism (one method name, different behaviour). Procedural programming has none of these as language features.
Can Java be written in a procedural style?
Yes. If you put everything in static methods inside one class and pass data around, you are writing procedural code in Java. The first example on this page does exactly that.

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

Apply for Demo Class →
Siva Prasad Galaba
Founder, CodeBegun · Staff Engineer

Founder of CodeBegun. 15+ years building Java systems at companies like Crunchyroll. Teaches Java, Spring Boot and system design the way the industry actually works, and mentors students through projects, mock interviews and placement preparation.

Technically reviewed by CodeBegun Technical TeamLast reviewed 5 December 2026 LinkedIn

More comparisons

View all
Chat with us