Object oriented concepts used in Java

Java is an Object-Oriented Language hence before learning java let us understand the object oriented Concepts first.

Object

An object in the software world means a bundle of related variables and functions known as methods variables and functions known as methods. Software objects are often used to model real-world objects you find in everyday life.

The real world objects and software objects share two characteristics :

1. State : condition of an item.
2. Behaviour : Observable effects of an operation or event including its results.

State can be of two types : Active state which reflects the behaviour and Passive State refers to state which does not change which does not change. The behaviour of an object forms the interface to the external world.

Class
A class is a blueprint or prototype that defines the variables and the methods (or funtions) common to all objects of a certain kind.

Constituents of a class are :

1.Member Variable:Variables declared with in a class

2.Member Functions : Functions or methods declared within the class. These methods operate upon the member variables of the class.

So a class is a definition of a set of data and methods. When memory space for this data is actually allocated, we say that class is instantiated i.e an object is created.Class defines how the object should be. Object is an instance of a class. Each instance of a class will have its own data.

Features of Object Oriented Programming

Abstraction is the process of exposing the relevant things and ignoring the irrelevant details. The easiest way to understand and appreciate this concept of handling complexity is by studying the example of Globe, a model/prototype of earth that is used by students to understand its geography. Globe provides only that information that is required and if too much of information is mentioned in it i.e. streets, lakes etc, it becomes too complex to comprehend. Hence Globe abstracts unwanted information and makes it easy to comprehend the complex earth.

Encapsulation is the mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse.
The data is not accessible to the outside world and only those functions that are wrapped in the class can access it.
These functions provide interface between the object data and program. The insulation of the data from the direct access by the program is called data hiding.

In OOP, code and data are merged into an object so that the user of an object can never peek inside the box. This is defined as encapsulation (i.e. Object is a capsule encapsulating data and behavior). All communication to it is throughmessages (i.e function calls which we use to communicate to the object). Messages define the interface to the object. Everything an object can do is represented by its message interface. Therefore, we need not know anything about what is in the object when we use it.

Inheritance is the process by which one class acquires the properties and functionalities of another class. This is important because it supports the concept of hierarchical classification. Inheritance provides the idea of re usability of code and each sub class defines only those features that are unique to it.

Polymorphism is a feature that allows one interface to be used for a general class of actions. An operation may exhibit different behaviour in different instances. The behaviour depends on the types of data used in the operation. It plays an important role in allowing objects having different internal structures to share the same external interface. Polymorphism is extensively used in implementing inheritance.

Leave a Reply

Your email address will not be published. Required fields are marked *