BASICS OF JAVA

What is Object Oriented Programming? What are OOPS concepts in Java?🤔

Sowjanya Sunkavalli
5 min readOct 31, 2022

Hello Everyone🙌

Hope everyone is going great with your continuous learning.✌️

Lets, Jump into the Topic…Okay, we keep on hearing Object Oriented Programming, and OOPS Concepts in our everyday coding life…

What actually Object Oriented Programming and why it is called so?

What are OOPS Concepts that everyone says are pillars for Object Oriented Programming?

Okay, in this blog we will learn briefly about this topic.

What is Object Oriented Programming?

Java is called an Object Oriented Programming Language. This means in a simple way we can say everything in Java Programming is considered an Object which contains data and functions and this object belongs to a particular class. Here class is a type of entity and object is instance of class.

Not only Java the majority of widely used programming languages, including Python, C++, C#, Ruby, etc., adhere to the object-oriented paradigm.

Major Advantage of Object-Oriented Programming

In the end, object-oriented programming is all about taking a complex issue and breaking it down into manageable pieces. You create a class that accomplishes what you require for each mini-problem. Then, the best part, you can reuse those classes, which speeds up solving the subsequent problems.

Okay, we have been told that Object Oriented Programming Language consists of Class and Object.

What are Class and Object?

Classes are user-defined data types that act as the blueprint for individual objects, attributes and methods.

Objects are instances of a class created with specifically defined data. Objects can correspond to real-world objects or abstract entities.

For Example, let’s say a Car is a type of Class whereas its instances such as a Tesla, Toyota, Ford etc serve as an Object of Class Car.

As we said that Class contains Attributes(state) and Methods (Behaviour), we can consider the following as Class Car attributes and Methods.

Attributes can be the Price, Speed, Color, Weight etc., of the car.

Methods can be changeGear(), slowSpeed(), brake() etc.,

When coming to the Object, let's Say the Object is Mini cooper.

So here Mini cooper is an instance of a Class Type Car and it has defined specific attributes and Methods.

Class and Object (Source: codeavial)

So far we have seen a brief idea on Class and Object, let’s jump into the Principles of Object Oriented Programming language i.e Inheritance, Polymorphism, Abstraction and Encapsulation.

In this blog we will learn briefly about the Principles in the coming blog we will learn the in-depth details of each Principle.

Inheritance

The concept of inheritance in Java refers to the transfer of properties from one class to another, such as the relationship between a Mom and daughter. Inheritance in Java is a process of acquiring all the behaviours of a parent object to child object.

Inheritance

In the above figure, we can see say inheritance as daughter class inheriting the variables and methods of the mom parent class. Here Mom is called Base class or Parent Class and Daughter is called Derived Class or Child Class.

Here, Inheritance is furthur classified into 4 types as follows

Types of Inheritance (Source : Simple Snippets)

Polymorphism

Polymorphism, where “poly” stands for numerous and “morph” for form, refers to taking on several forms. It refers to an object’s, function’s, or variable’s capacity to assume several forms.

It is the ability of a class to offer various implementations of a method depending on the kind of object that is passed to the method. To put it simply, polymorphism in Java allows us to perform the same action in many different ways.

Polymorphism is furthur divided into two types as follows

Polymorphism Types (Source : Simplileran)

Abstraction

Data abstraction is the process of withholding some information from the user and only displaying what is absolutely necessary. Abstract classes or interfaces can be used to accomplish abstraction.

Simply said, abstraction “displays” only the necessary features of objects while “hiding” the unnecessary specifics.

Abstraction

Abstraction in Java is achieved by using Abstract class and Interface.

Encapsulation

In Java, encapsulation refers to the practice of combining data (variables) and the code that affects them (methods) into a single unit. The variables of a class are protected by an encapsulation so that only the methods of the class can access them. Getters ans Setters methods are used to get the data.

Encapsulation

So, this is all a brief about OOPS Concepts in Java. It’s not yet done we still need to learn on how Inheritance, Polymorphism , Abstraction and Encapsulation is implemented and how many ways to achieve them and many more in-depth concepts.

I hope you like this blog, comment below your suggestions / feedback / concerns if any🙌

In the coming blog we will learn implementations of each OOPS Principle with a coding example. Till then keep learning and keep coding✌️

Thanks,

Sowjanya Sunkavalli

--

--

Sowjanya Sunkavalli

Hey there, I’m Sowjanya, a passionate Quality Assurance Engineer👩🏻‍💻🪲 who loves to write, share and learn.