Wednesday, January 15, 2020

OOPS in Java

Object-Oriented Programming with Java

Java is an Object-oriented programming language. OOP(Object-Oriented Programming) is a programming paradighm and it is very helpful for designing and creating software applications in extremely manageable, scalable, maintainable, easy to debug, cleaner and readable way. This approach is very much closer to real-world problem solving approach of human beings.

What are the required features for a programming language to become an Object-Oriented Programming language?


Class is a set of objects. Class is used to classify, things having common attributes and behaviours. For example, Student is a class in which all people studying can be kept.


Basically, an object is made of three components Attributes, Behaviours and Identity (State).

Each individual student that belongs to class Student will be an object of this class.

A language is said to object-oriented if it is object based and has the power of Polymorphism, Inheritance, Encapsulation and Abstraction.


Encapsulation binds code and data together. Encapsulation keeps data safe from outside interferences and misuse. The basis of encapsulation in Java is “CLASS”. “OBJECTS” are instances of class. Class “DOES” encapsulate the complexity of implementation inside. Encapsulation is “hiding details at the level of implementation”.Java beans are the example of fully encapsulated Java classes. Encapsulation provides us complete control over data.


Inheritance is “Acquisition of the data and behaviour of one class from other”. Actual essence of Inheritance is REUSE of code, REDUCE complexity and improve the manageability. Inheritance introduces hierarchal implementation. Java uses single inheritance model. One subclass can have one(and only one) super class. “extends” keyword is used to implement inheritance. A subclass include all the members of its superclass (Constructor are exception).


Polymorphism means “MANY FORMS”. Polymorphism allows “One interface-multiple methods”. Polymorphism is used for the creation of generic interface to a group of relative activities. Polymorphism in Java is achieved by method overloading and method overriding.


Abstraction allows us to show only the relevant attributes of objects and hide the unnecessary details. Abstraction reduces the programming efforts and thereby the complexity. An end-user using the application need not be concerned about how a particular feature is implemented. He/she can just use the features as required.

Thus in abstraction, we deal with ideas and not the events. This means that we hide the implementation details from the user and expose only the functionality to the end-user. Thereby the user will only know “what it does” rather than “how it does”.

In Java abstraction can be applied by either using Abstract classes or Java Interfaces. Abstract classes can provide us partial abstraction. Interfaces always provides complete abstraction.