What is Object-Oriented Programming?
What is Object-Oriented Programming?
Every programmer eventually runs into the same wall: a program that started small but grew into a tangle of functions and global variables that nobody wants to touch anymore. Object-Oriented Programming (OOP) is the response to that problem. Instead of organising a program around a sequence of steps, OOP organises it around objects, self-contained units that bundle data and behaviour together, much like the real things they represent.
OOP vs Procedural Programming
Procedural programming, the style used in languages like C, treats a program as a list of instructions executed top to bottom, with data and functions kept separate. You pass data into functions, the functions act on it, and the data has no inherent connection to the logic that operates on it.
Object-oriented programming flips this. Data and the functions that operate on it (called methods) live together inside an object. A BankAccount object does not just hold a balance; it also knows how to deposit, withdraw, and check that balance, all in one place.
Aspect | Procedural Programming | Object-Oriented Programming |
Organisation | Functions and data are separate | Data and methods are bundled into objects |
Reusability | Limited; functions are often rewritten per use case | High; classes can be reused and extended |
Data security | Data is usually globally accessible | Data can be hidden using encapsulation |
Real-world mapping | Models a process as a sequence of steps | Models real-world entities as objects |
Scalability | Becomes harder to manage as programs grow | Designed to scale through modular classes |
Neither style is inherently 'better' in every situation, but OOP tends to age far more gracefully as a codebase grows, because related data and logic stay physically close together instead of scattering across the file.
Why Java is an OOP Language
Java was designed from the ground up around objects. Almost everything in a Java program, aside from a handful of primitive types like int and boolean, exists as an object, and every line of executable code must live inside a class. This is not optional in Java the way it can be in some other languages.
- Everything (except primitives) is an object: strings, arrays, and even exceptions are objects in Java.
- Classes are mandatory: you cannot write a stray function floating outside a class; even the entry point, main(), must sit inside one.
- Strong support for all four pillars: encapsulation, inheritance, polymorphism, and abstraction are built into the language's syntax, not bolted on as an afterthought.
- Platform independence pairs naturally with OOP: well-designed, encapsulated classes are easier to reuse across different parts of a 'write once, run anywhere' codebase.
public class Main {
public static void main(String[] args) {
System.out.println("Hello, Java is class-based!");
}
}
Did You Know?
Java is often called a 'pure' OOP language, but it is not 100% pure in the strictest sense, because primitive types like int, double, and boolean are not objects. Fully pure OOP languages, like Smalltalk, treat even numbers as objects.
Real-World Analogy for OOP
The easiest way to internalise OOP is to stop thinking about code for a moment and think about a car factory. The factory does not build every car from raw metal by hand each time; it has a blueprint, a design that specifies what every car of a given model will have: four wheels, an engine, a colour, a number plate.
That blueprint is a class. Every individual car that rolls off the assembly line, your neighbour's red hatchback, the taxi outside your office, is an object: a concrete instance built from the same blueprint, but with its own specific values for colour, number plate, and mileage.
Real-World Concept | OOP Equivalent |
Car blueprint | Class |
An individual car | Object (instance) |
Colour, number plate, mileage | Fields (attributes) |
Start engine, brake, honk horn | Methods (behaviours) |
Hatchback is a type of Car | Inheritance |
Keep this analogy in mind as you move through the rest of this tutorial. Every new OOP term you encounter- class, object, constructor, inheritance- maps back to something you already understand intuitively about how blueprints and real-world things relate to each other.










