
Java is Object Oriented programming language which means java programs use classes and objects. In order to write a program in Java we need atleast a class or an object. A class is a module which contains data and methods to achieve task.
Each class can perform same tasks for which we write methods in a class. This approach is called Object Oriented approach. An object oriented approach is a methodology by which we can complete tasks in a better way in programming language.
This approach is built from “objects”, which represent anything that exists in the real world. For example, all animals are objects, all humans are objects. So we use this approach in programming then it is called OOPs.
In OOP concept, you design a computer program and create objects to interact with each other.
Table of Contents
What is the need for Object Oriented programming?
We prefer object oriented programming because of following reasons:
- Software is easy to understand if you develop using OOPS concept.
- The readability, understandability, and maintainability of the code increase.
- If you are going to develop big software then you should prefer oops concept which is easy to write and manage.
Java, C++, Javascript, Python, PHP are the example of major Object-Oriented Programming languages.
Features of Object Oriented Programming
The main features related to OOP are as follows:
- Class and Object
- Abstraction
- Encapsulation
- Inheritance
- Polymorphism
Let’s discuss all the feature of object oriented approach in details one by one.
1) Class and Object
Class is a model for creating objects and it defines shape and behavior of an object and describes the properties and actions. In other words, a class represents a group name given to several objects that have similar properties and actions.
In short, an object is anything that actually exists in the world. If we consider a program then and object is an instance of class which has properties and performs specific actions.
public class Main { // Class Name
private int var1;
public int getVar1() { // Getter Method
return var1;
}
pubilc void setVar1(int var1) { // Setter Method
this.var1 = var1;
}
}
2) Abstraction
A class may contain a lot of data that is not useful to the user, the user may only need some part of the available data. In this case, you can hide unnecessary data from the user and present only the data that is of interest to the user.
So Abstraction is the process of hiding unnecessary information and showing only essential details to the user.
3) Encapsulation
In encapsulation is a process in which we bind all variables/data and methods together in a single unit. For example, we write the variables and methods inside the class that means we are binding them together.
Encapsulation separates the members of one class from the members of another class hence each object shares different memory. This concept helps the programmers to use the same name for members in different classes.
4) Inheritance
Inheritance is a concept of creating new classes from existing classes, so the newly created class acquire all the features of the existing classes.
A super class may have one or more sub classes but a subclass can have only one super class. And we use java extends keyword to inherit other class.
Syntax of Java Inheritance
public class <sub-class> extends <super-class> {
// Class body
}
5) Polymorphism
Polymorphism provides the flexibility in writing programs in such a way that the programmer can use same method call to perform different operations, so we can say that a programmer reuse the code for different purpose.
There are two types of polymorphism in object oriented language:
- Compile-time polymorphism
- Runtime polymorphism
Advantages of Object Oriented Programming
There are many benefits of using OOP concept which are as follow:
- Simple and clear structure of OOP program.
- Code reusability
- Partitioning in OOPs project work is very easy.
- Faster and easier execution.
- Due to message passing technique, the communication between objects are easy.
- Flexibility in Polymorphism and easy troubleshooting.
- You can save lots of time to maintain and modify the existing codes, on the other hand you can save lots of cost.
In conclusion, if you have come to know about the JDBC driver then your next step should be the Java connectivity with the database. Hope you liked the article on JDBC Driver in Java. Feel free to contact geekcer.code@gmail.com or you can write a comment if you have any doubts and questions.