DEV Community

Cover image for 4 Pillars Of OOP in Java
Samvel
Samvel

Posted on

4 Pillars Of OOP in Java

In the modern programming world, there are five types of programming languages.

  1. Procedural programming languages
  2. Functional programming languages
  3. Object-oriented programming languages
  4. Scripting languages
  5. Logic programming languages

Java, the focus of this post, is an object-oriented programming (OOP) language. Object-oriented programming is a computer programming model that organizes software design around data and objects rather than functions and logic. An object can be defined as a data field that has unique attributes and behavior.

Four pillars of OOP
Image description
Object-oriented programming uses Four pillars of OOPs to create efficient software systems: encapsulation, abstraction, inheritance, and polymorphism.

Encapsulation

At the heart of encapsulation is the bundling of data and methods that operate on that data within a single unit known as a class. A class is a blueprint for objects, defining their properties (attributes or fields) and behaviors (methods). This bundling ensures that the internal workings of an object are hidden from the outside world, promoting data integrity and security.

Abstraction

Abstraction involves simplifying complex systems by modeling classes based on essential properties. It allows developers to focus on high-level concerns without getting bogged down in the details. Abstract classes and interfaces in Java are key components of abstraction, providing a blueprint for other classes to implement.

Inheritance

Inheritance is a mechanism that allows a new class (subclass or derived class) to inherit attributes and behaviors from an existing class (superclass or base class). This fosters code reuse and establishes a hierarchy among classes, facilitating the creation of more specialized classes without duplicating code.

Polymorphism

Polymorphism, meaning "many forms," allows objects of different classes to be treated as objects of a common superclass. This can be method overloading (multiple methods with the same name but different parameters) and method overriding (providing a specific implementation for a method in a subclass).

Java's commitment to the four pillars of OOP β€” encapsulation, inheritance, polymorphism, and abstraction β€” empowers developers to write clean, modular, and maintainable code.

Top comments (0)