Java OOPs Concepts

On this page, we'll go over the fundamentals of OOPs. Inheritance, data binding, polymorphism, and other notions are all part of the Object-Oriented Programming paradigm. Simula is considered the first object-oriented programming language. A genuinely object-oriented programming language is a programming paradigm in which everything is represented as an object. Smalltalk is widely regarded as the first object-oriented programming language. Java is one of the most widely used object-oriented languages. The popular object-oriented languages are JavaC#PHPPythonC++, etc. Object-oriented programming's fundamental goal is to implement real-world things such as objects, classes, abstraction, inheritance, polymorphism, and so on. 

OOPs are acronyms for "out of the box thinking (Object-Oriented Programming System)

A real-world entity such as a pen, chair, table, computer, watch, and so on is referred to as an object. Object-Oriented Programming (OOP) is a programming methodology or paradigm that uses classes and objects to create a programme. It makes software development and maintenance easier by introducing the following concepts:

Apart from these concepts, there are some other terms which are used in Object-Oriented design:

  • Coupling
  • Cohesion
  • Association
  • Aggregation
  • Composition

Object

An object is any entity that has state and behaviour. For instance, a chair, pen, table, keyboard, bicycle, and so forth. It could be physical or conceptual in nature.

An instance of a class can be defined as an Object. An object holds an address and occupies memory space. Objects can communicate even if they are unaware of one other's data or code. The only thing that matters is the type of message that is accepted and the type of response that the objects provide.

A dog, for example, is an object since it has states such as colour, name, breed, and activities such as waving the tail, barking, and eating.

Class

The term "class" refers to a group of items. It's a logical thing. A class can alternatively be thought of as a blueprint from which an individual object can be created. Class doesn't take up any room.

Inheritance

Inheritance occurs when one object inherits all of the characteristics and actions of a parent object. It allows for code reuse. It's used to achieve polymorphism at runtime.

Polymorphism

Polymorphism occurs when a single task is completed in multiple ways. To persuade a buyer in a different way, for example, draw a form, triangle, rectangle, or other object.
To create polymorphism in Java, we employ method overloading and method overriding.
Another example is to say something; for example, a cat meows, a dog barks woofs, and so on.

Abstraction

Abstraction is the process of concealing internal features while displaying functionality. We don't know the internal processes of a phone call, for example.
To achieve abstraction in Java, we employ abstract classes and interfaces.

Encapsulation

Encapsulation is the process of joining (or wrapping) code and data into a single entity. A capsule, for example, is coated in various drugs.Encapsulation is demonstrated using a Java class. Because all data members are private in a Java bean, it is a fully enclosed class.

Coupling

Another class's knowledge, information, or dependency is referred to as coupling. It occurs when students are aware of one another's existence. There is strong coupling when a class contains the detailed information of another class. To display the visibility level of a class, method, or field in Java, we utilize the private, protected, and public modifiers. Because there is no concrete implementation, you can utilize interfaces for the weaker coupling.

Cohesion

The level of cohesion of a component that performs a single well-defined task is referred to as cohesion. A very coherent approach is used to complete a single well-defined task. The assignment will be divided into several segments using the weakly cohesive method. Because it contains I/O-related classes and interfaces, the java.io package is quite coherent. The java.util package, on the other hand, is a disjointed collection of classes and interfaces.

Association

The relationship between the things is represented through association. One object can be linked to one or more objects in this case. There are four different types of object associations:
One to One

One to Many

Many to One, and

Many to Many

Let's look at some real-life instances to better grasp the relationship. For instance, a country can have only one prime minister (one to one), while a prime minister can have a large number of ministers (one to many). Furthermore, several MPs can have the same prime minister (many to one), and numerous ministers can have multiple departments (many to many).
Unidirectional or bidirectional association is possible.

Aggregation

Aggregation is a method of attaining Association. Aggregation refers to a relationship in which one object's state includes other items. It symbolizes a shaky connection between objects. In Java, it's known as a has-a relationship. The is-a relationship, for example, is represented by inheritance. It's yet another way to recycle items.

Composition

Association can also be achieved through composition. The composition denotes a connection in which one thing includes other objects as part of its state. The enclosing item and the dependent object have a strong relationship. It is the state in which the things that make up the container have no independent existence. If you delete the parent object, it will be followed by the deletion of all child objects.

Advantage of OOPs over Procedure-oriented programming language

​​1) OOPs make development and maintenance easier, whereas procedure-oriented programming languages are difficult to handle as project sizes rise.
2) Data hiding is provided by OOPs, whereas global data can be accessed from anywhere in a procedure-oriented programming language.

Figure: Data Representation in Procedure-Oriented Programming

Figure: Data Representation in Object-Oriented Programming
3) OOPs allow for considerably more effective simulation of real-world events. If we use the Object-Oriented Programming language, we may propose a solution to a real-world problem.

What is the difference between an object-oriented programming language and object-based programming language?

Except for inheritance, an object-based programming language follows all of the features of OOPs. Object-based programming languages include JavaScript and VBScript.


 



Contact Us logo Whatsapp