FREE E LEARNING PLATFORM
HOMEEXCEPTIONSOOPSJVMINTRO
 

Object Oriented Programming System

noidatut course






OOPS

Object Oriented Programming system is an approach to program organization and development which attempts to eliminate and remove the pitfalls and drawbacks of conventional programming methods by incorporating the best structured programming features with several new concepts.
The major objective of object oriented approach is to eliminate some of the flaws encountered in the procedural approach. OOPS treats data as a critical element in the program development and does not allow it to flow freely around the system. It ties data more closely to the functions that operate on it and protects it from unintentional modification by other functions.
OOPs allows us to decompose a problem into a number of entities called objects and then build data and functions.
The combination of data and methods make up an object.
Object Oriented System is an approach that provides a way of modularizing programs by creating partioned memory area for both data and functions that can be used as templates for creating copies of such modules on demand.


OOPS features are :

1. Class and Objects
2. Abstraction and Data hiding
3. Encapsulation
4. Inheritance
5. Polymorphism
6. Dynamic binding

Basic Concepts of Object Oriented Programming

1. Objects and Classes : Objects are basic run time entities in object oriented system. They may represent a person, a place, a bank account or any item that the program may handle.
They may also represent user defined data types such as vectors and lists. Any programming problem is analysed in terms of objects and the nature of communication between them.
When a program is executed, the objects interact by sending messages to one another.
For Example customer and account are two objects in a banking program, then customer object may send a message to the account object requesting for balance.
Objects contain data and code to manipulate that data. The entire set of data and code of an object can be made a user defined data type by using the concept of class.
Class is considered as complex data types and is a collection of objects of similar types. Class is a collection of functions and data types which is further accessed by the objects. Classes are user defined data types. The wrapping up of data and methods into single unit is classed a class.
Example 2:

Class student
{
public int roll;
public char name[100];
public void student()
{
System.out.println("First Class ");
}
}
public class example
{
public static void main(String args[])
{
student obj = new student ();
obj.student();
System.out.println("The First Program");
}
}

Data Encapsulation

The wrapping up of data and methods into a single unit ( called class ) is known as Encapsulation . Data Encapsulation is one of the most striking and important features of OOPS.
The data is not accesible to the outside world and only those methods which are wrapped in the class can access it . These methods provide the interface between the objects data and the program. This insulation of data from direct access by the program is called Data hiding. Encapsulation makes it possible for objects to be treated like black boxes, each performing a specific task without any concern for internal implementation.

Example

Class student
{
public int roll;
public char name[100];
private fees;
public void student()
{
System.out.println("First Class ");
}
}
public class example
{
public static void main(String args[])
{
student obj = new student ();
obj.student();
System.out.println("The First Program");
}
}

Data Abstraction

Abstraction refers to the act of representing essential features without including the background details or explanations. Classes use the concept of abstraction and are defined as a list of abstract attributes such as size, weight, cost and methods that operate on these attributes. They encapsulate all the essential properties of the objects that are to be created. Abstraction is one of the most important features of OOPS.

Example

Class student
{
public int roll;
public char name[100];
private fees;

public void student()
{
System.out.println("First Class ");
}
}
public class example
{
public static void main(String args[])
{
student obj = new student ();
obj.student();
System.out.println("The First Program");
}
}

Inheritance

Inheritance is the process by which objects of one class acquire the properties of objects of another class. Inheritance supports concept of hierarchical classification. The concept of Inheritance provides the idea of reusability. We can add up additional features to an existing class without modifying it. This is possible by deriving a new class from the existing one. The new class will have the combined features of both the classes.
Inheritance allows the programmer to reuse a class that is almost but not exactly the programmer needs.
The derived class is known as the sub class. For Example Grandfather is a very good dancer, and father is avery good singer, the child can have property of being a very good dancer but by inheritance we can say that he is a very good dancer as well as a singer.

Second Example :

Class Room
{
int length;
int breadth;
Room ( int x, int y)
{
length = x;
breadth = y;
}
int area()
{
return ( length * breadth);
}}
class bedroom extends Room
{
int height;
bedroom ( int x , int y , int z )
{
super ( x, y) // pass values to super class )
height = z;
}
int volume ()
{
return ( length * breadth * height );
}
}
Class inherit
public static void mein ( String args[])
{
bedroom room 1 = new bedroom(14, 12, 10 );
int area1 = room1.area();//super class method
int volume1 = room1.volume(); // baseclass method
System.out.println( " Area1 = " + area);
System.out.println("volume = " + volume );
}

Types of Inheritance

1. Single Inheritance ( Only one Super Class )
2. Multiple Inheritance (Serveral Super Classes )
3. Hierarchical Inheritance ( One Super Class and many sub classes )
4. Multi Level Inheritance ( Derived from a Derived class )

Polymorphism

Polymorphism ( Poly means many and morphism means forms - from there it came taking more than one form. Polymorphism is another important concept of OOPS. It means to take more than one form. For example an operation may exihibit different behaviour in different instances. The behaviour depends upon the types of data used in the operation.
For Example , consider the operation of addition. For two numbers, the operation will generate a sum. If the operands are strings, then the operation would produce a third string by concatenation.
Polymorphism is of two types dynamic polymorphism and static polymorphism.

Dynamic Binding :

Dynamic Binding : Binding refers to the linking of a procedure call to the code to be executed in the response of the call. Dynamic Binding means that the code associated with a given procedure call is not known until the time of call at run time. It is associated with polymorphism and inheritance. It is also known as late binding as the set of codes which would be running is not known till time of execution.

Message Communication

An object oriented program consists of a set of objects that communicate with each other. The Process of programming in an object oriented language, therefor involves the following basic steps :
1. Creating Class that define the objects and their behaviour.
2. Creating objects from class definitions.
3. Establishing communication among objects.
Objects communicate with one another by sending and receiving information.
A message for an object is a request for execution of a procedure and therefore will invoke a method ( procedure) in receiving object that generates the desired results.
Message passing involves specifying the name of the object and the name of the method (message ) and the information to be sent.

For example :

Employee.Salary( name);
Employee is the object , salary is the message and name is the information.
Objects have a life cycle which can be created a destroyed. Communication with an object is feasible as long as it is alive.

Benefits of oops and application of oops

Benefits of OOPS :
1. Through inheritance , we can eliminate the redundant code and extend the use of existing classes.
2. The principle of data hiding helps the programmer to build secure programs that cannot be invaded by code in other parts of the programs.
3. It is possible to have multiple objects to coexist without any interference.
4. Software complexity can easily be managed.
5. Message passing techniques for communication between objects make the interface description with external systems much simpler.
6. Object oriented systems can easily be upgraded from small to large systems.
7. It is easy to partition the work in project based objects.
8. It is possible to map objects in the problem domain to those objects in program

Application of OOPS

The application of OOPS includes :
1. Real Time systems
2. Simulation and modelling
3. Object oriented databases
4. Hypertext, hypermedia and expertext
5. AI and Expert Systems.
6. Neural Networks and parallel programming
7. Decision support and office automation
8. CIM / CAD

You may also Find this interesting

JAVA Static Keyword

JAVA Inheritance

JAVA Types of Inheritance

JAVA Aggregation

JAVA Association


noidatut course




Leave Comment