OOPS Concept in Java || What is Object Oriented Programming?

Objects are the basic building block of Object-Oriented Programming System(OOPs). The real world Objects have characteristics such as state and behavior.

For example, the human being has a state, such as nature, color, age and height and behavior such as walking, dancing, and sleeping. All the objects in oops are based on the real-world having specific state and behavior.

Concepts of OOPs in Java:

  • Objects
  • Classes
  • Data Abstraction
  • Encapsulation
  • Inheritance
  • Polymorphism

Now lets us understand the concept in brief with real-world examples.

What is Object in Java?

Objects are the basic run-time entities in an object-oriented system Object is the main approach which is used primarily in this structure.

The programming problem is analyzed In terms of objects and nature communication between them. When a program is executed, the object interact with each other by sending messages. different objects also interact with each other by sending messages.

Different objects can also interact with each other without knowing the details of their data or code.

What is Classe in Java?

A class is a collection of objects of a similar type. Once a class is defined, any number of objects can be created which belong to that class.

A sample code of a class is given below:

public class Dog

{

String bread;

int age;

String color;

void barking()

{

}

void hungry()

{

}

void sleeping()

{

}

What is Encapsulation in Java?

Encapsulation implies that the non-essential details o an object hidden from the user and access is provided to its essential tails. Hence encapsulation is also called information hiding.

In short, encapsulation is the feature that provides security to the data and methods of a class.

let’s relate it with real-world examples for better understanding.

Example:

When you plug in the cord of a vacuum cleaner and switch it the vacuum cleaner starts functioning. An end-user needs not to know the working principle of a vacuum cleaner to convert electricity into power. the switch of the vacuum cleaner encapsulates the complex process of conversion of electricity into suction power. The complexity of an object is hidden as a result of encapsulation.

What is Abstraction in Java?

Its Simple, abstraction refers to the act of representing essential features but including the background details or explanations.

let’s relate it with real-world examples for better understanding.

for example:

when you want to send e-mail messages you should know the process of writing e-mails messages and sending it to the receiver. however, it is not necessary or you to know the entire process of sending the email messages across the network.

What is Inheritance in Java?

Inheritance is the process by which objects can acquire properties of objects of other classes. in oop, inheritance provides reusability, like, adding additional features to an existing class without modifying it.

This is achieved by deriving a new class from the existing one. the new class will have combined features of both the class

What is Polymorphism in Java?

This term referred to as the ability to take more than one form operation may exhibit different behaviors in different instances behavior depends on the data types used in the operation polymorphism is extensively used in implementing inheritance.

Advantages of OOP:

  • Object-oriented Programming has the following  advantages conventional approaches:
  • OOP provides a clear modular structure for programs that makes it good for defining abstract datatypes implementations details are hidden and the unit has clearly defined interface.
  • OOP makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones.
  • OOP provides a good framework for code libraries supplied software components that can be easily adapted modifie3d by the programmer. this is particularly used to develop graphical user interfaces.