Notes – Object Oriented Programming in Java

Java is known as a pure object-oriented programming language, meaning it is designed around the concept of objects and classes.

Letโ€™s explore what this means in simple terms.


What is Object-Oriented Programming?

  • OOP is a programming style where real-world entities like person, car, bank account are represented as objects.
  • These objects contain data (fields/attributes) and behavior (methods/functions).

Example:

class Car {
String color;
void drive() {
System.out.println("Car is moving");
}
}

4 Main Pillars of OOP in Java


ConceptDescription
EncapsulationWrapping data (variables) and code (methods) together in one unit, i.e., a class.
InheritanceOne class (child) can reuse the features of another class (parent).
PolymorphismOne function behaves differently in different scenarios.
AbstractionHiding internal details and showing only the essential features.

Java as an Object-Oriented Language

  • Everything in Java revolves around classes and objects.
  • Java uses OOP to structure code for better reusability, scalability, and maintenance.

Important Terms in OOP (Java)


TermDescription
ClassBlueprint of an object; defines properties and methods.
ObjectInstance of a class; occupies memory.
MethodA function defined inside a class.
ConstructorSpecial method used to initialize objects.
Access ModifiersKeywords like public, private, and protected to control visibility.

Why OOP is Important in Java?

  • Helps organize code better.
  • Reduces duplication and promotes code reuse.
  • Makes complex applications easier to manage and scale.

Example in Real Life

Class: Dog
Object: Your pet dog, Max
Data (fields): name = โ€œMaxโ€, breed = โ€œLabradorโ€
Behavior (methods): bark(), sleep()

class Dog {
String name;
void bark() {
System.out.println(name + " is barking");
}
}

Summary

Java is object-oriented because:

  • It supports all core OOP principles (Encapsulation, Inheritance, Polymorphism, Abstraction).
  • Programs are structured using classes and objects.
  • It improves modularity, reusability, and real-world modeling in programming.