What is OOPs in Java

In this article we learn the what is OOPs in java, types of OOPs, benefits of OOPs and Challenges associated with OOPs in Java.

What is OOPs in Java?

Object-Oriented Programming refers to programming that helps us to create the objects that we want and create methods to handle these objects. The principle of OOPs in java is to create objects, reuse the objects throughout the program, and manipulate these objects.

The primary objective of OOPs in java is to enhance the maintainability and flexibility of applications. Object-oriented programming brings together data, and its behavior (methods) in a single location (object) makes it easier to understand how a program works.

 

Types of OOPs in Java

1. Object

2. Class

3. Inheritance

4. Polymorphism

5. Encapsulation

6. Abstraction

1. Object

i) An object is an instance of a class which is pointing to its own memory.

ii) An object is an identifiable entity with some characteristics, state, and behavior.

iii) Class Object is the root of the class hierarchy. Every class has Object as a superclass. All objects, including arrays, implement the methods of this class.

iv) Object is created through new keyword

 2. Class

i) A class in Java is a blueprint which all the data.

ii) It describes the state and behavior of a specific object.

iii) In Java, we cannot declare a top-level class as private. Java allows only public and default access specifiers for top-level classes. We can declare inner classes as private.

iv) We can include any type of the variables in Java – local, global variables.

v) There can be only one public class in a single program and its name should be the same as the name of the Java file. There can be more than one non-public classes in a single Java file.

vi) A public class is visible to all classes from all the packages.

vii) A class with default access is visible only to the classes within the same package.

viii) We can also use the non-access modifiers for the class such as final, abstract and strictfp. This is called default/package accessibility.

ix) We cannot create an object or instance of an abstract class.

x) No subclasses or child class can be created from a class that is declared as final.

3. Inheritance

Inheritance can be defined as the process where one class acquires the properties (methods and fields) of another.

Important Terms in Java Inheritance

1. Class: Class is a user-defined data type in Java that is basically a group of objects. It is a blueprint or template from which we create objects.

2. Super Class: The class whose features and functionalities are being inherited or used is known as the superclass or a base class or a parent class.

3. Sub Class: The class that inherits the properties and features from another class is known as a subclass or a derived class or extended class or child class. The subclass can add its own features and functions in addition to the fields and methods of its superclass or the parent class.

4. Polymorphism

i) Poly and Morphs. The word “poly” means many and “morphs” means forms. So, polymorphism means many forms.

ii) The virtue by which the same action can be performed by objects of different classes and each object responds in a different way depending on its class is called Polymorphism.

5. Encapsulation

Encapsulation in Java is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit. In encapsulation, the variables of a class will be hidden from other classes and can be accessed only through the methods of their current class. Therefore, it is also known as data hiding.

To achieve encapsulation in Java

1. Declare the variables of a class as private, so that they cannot be accessed directly from outside the class.

2. Provide public setter and getter methods to modify and view the variables values.

6. Abstraction

i) The meaning of the word “Abstraction”, in general words, is the process of working with ideas rather than their implementation.

ii) It is a process of hiding the implementation details and showing only functionality to the user.

Benefits of OOPs in Java

1. Improved productivity during software development

2. Improved software maintainability

3. Faster development sprints

4. Lower cost of development

5. Higher quality software

Challenges associated with OOPs in Java

1. Steep learning curve

2. Larger program size

3. Slower program execution

4. It is not a one-size-fits-all solution

Other Popular Articles

Argument in Java | Parameters in Java

Leave a Comment