Java Programming

Java Important Concepts

Java is the most popular programming language available in today’s market. It has first appeared in 1995 developed by Sun microsystem. In this post, we will learn the basic & important concepts of Java which we see in our day to day life.

1. Features of Object-Oriented Programming

Object-oriented programming is far better than procedural-oriented programming languages in many aspects. Some of the advanced features provided by Object-oriented programming are Object, Class, Data Abstraction, Encapsulation, Inheritance, Polymorphism, etc.

Objects

Objects are basic run-time entities having its own characteristics. Think of an object as a real-world entity. An object may be the behavior or any state like a table, chair, animal, etc.  It is an instance of a class. Generally, in Java programming, we need to create an object of a class to access the data member & the member function of the classes. A class may contain a number of objects & we can access its data member or the member function using the dot operator (“.”) followed by the method or data member name.

For example, suppose we need to create a class named as “college” which may contain some data members & member functions. So if we need to access these data member & member function in our main() method then firstly we need to create the object of that class as like object – “student”.

The basic syntax which we use to create the object of the class is,

Class_name Object_name = new Class_name();

Class

A class is a collection of objects of similar types. It is the combination of data members & the member functions. Think about a class as a real-world thing. It is made up by combining different entities to make a single entity. For example, a real-world entity car may also be a class with different entities combined in it as like its tires, brakes, color, mirrors, etc. Each one has its own characteristics & behaviors and is combined together to form a car.

A class is always defined by the user itself & that’s why it is also termed as a user-defined data type. It can be created by the following syntax:

class Class_Name
{
access_specifier:
// data member & member function
}
Data Abstraction

Data Abstraction is a special feature of object-oriented programming which allows us to hide irrelevant data & show only the essential one so that our program becomes more safe & secure. It can be generally implemented by the use of class in the program.

For example, in a car, we can only see its brakes, accelerator, handle, etc rather than its internal mechanism. Similarly to save our data & information from unauthorized access, we can use data abstraction mechanism to hide our important data & show only the essential one.

Encapsulation

Encapsulation is the mechanism of binding different data in single unit i.e., data member & member functions in a class. Encapsulation is beneficial in many aspects. It enhances the feature of code reusability i.e., once we write the code & bind it in a single unit then we have the permission to use that code in our program as many time as we wanted.

Some of the advantages of using Encapsulation are data hiding, code reusability, it increases flexibility, the codes can be easily tested & debugged.

Inheritance

Inheritance is one of the best features of object-oriented programming which allows a class to inherit the properties of another class. The class which is inherited by other class is known as base class & the class which inherits the properties of another class is known as a subclass. It will enhance the feature of code reusability.

Polymorphism

Polymorphism is a combination of two words i.e., poly & morphism which means having multiple forms. Polymorphism gives us the ability to create or define different entities with the same name but having different parameters.

There are basically two types of polymorphism available in Object-oriented programming:

  • Compile-time polymorphism
  • Runtime polymorphism

 


 

 

 

Leave a Reply