C

Core Java tutorial for beginners

Clean • Professional

Core Java – Object-Oriented Programming (OOP) in Java Overview

1 minute

Object-Oriented Programming (OOP) in Java

Object-Oriented Programming (OOP) is the foundation of Java. It allows developers to write modular, reusable, and maintainable code by focusing on objects rather than procedures.

In Java, almost everything is treated as an object, except primitive types. Understanding OOP is essential for building robust Java applications.


Why OOP in Java?

learn code with durgesh images

  • Modularity: Break programs into classes and objects.
  • Reusability: Use inheritance to reuse existing code.
  • Maintainability: Easier to update and debug.
  • Security: Encapsulation hides sensitive data.
  • Flexibility: Polymorphism allows dynamic method behavior.

Core Concepts of Java OOP

  1. Class: Blueprint for creating objects.
  2. Object: Instance of a class with state (attributes) and behavior (methods).
  3. Encapsulation: Hiding data using private fields and public getters/setters.
  4. Inheritance: Allows a class to inherit properties and methods from another.
  5. Polymorphism: One interface, multiple forms; achieved via method overloading and overriding.
  6. Abstraction: Hiding implementation details using abstract classes or interfaces.

Example – Simple OOP in Java

class Car {
    String color;
    int speed;

    void drive() {
        System.out.println("Car is driving at " + speed + " km/h");
    }
}

public class Main {
    public static void main(String[] args) {
        Car myCar = new Car();
        myCar.color = "Red";
        myCar.speed = 80;
        myCar.drive();
    }
}

Output:

Car is driving at 80 km/h

Notes:

  • Car → class
  • myCar → object
  • Encapsulation and methods define state and behavior.

Points to Remember

  • Java is fundamentally object-oriented.
  • OOP enables code reuse, modularity, and better organization.
  • Learning OOP is essential before diving into advanced Java concepts like Collections, Multithreading, and JDBC.

Article 0 of 0