Abstraction in Java


Interface in Java Encapsulation in Java

Abstraction in Java

Abstraction is the concept of exposing only the required essential characteristics and behavior with respect to a context.

Hiding of data is known as data abstraction. In object oriented programming language this is implemented automatically while writing the code in the form of class and object.

Real Life Example of Abstraction in Java

Abstraction shows only important things to the user and hides the internal details, for example, when we ride a bike, we only know about how to ride bikes but can not know about how it work? And also we do not know the internal functionality of a bike.

real life example of abstraction

Another real life example of Abstraction is ATM Machine; All are performing operations on the ATM machine like cash withdrawal, money transfer, retrieve mini-statement…etc. but we can't know internal details about ATM.

real life example of abstraction

Note: Data abstraction can be used to provide security for the data from the unauthorized methods.

Note: In Java language data abstraction can achieve using class.

Example of Abstraction

class Customer
int account_no;
float balance_Amt;
String name;
int age;
String address;
void balance_inquiry()
/* to perform balance inquiry only account number
is required that means remaining properties 
are hidden for balance inquiry method */
void fund_Transfer()
/* To transfer the fund account number and 
balance is required and remaining properties 
are hidden for fund transfer method */

How to achieve Abstraction ?

There are two ways to achieve abstraction in java

  • Abstract class (0 to 100%)
  • Interface (Achieve 100% abstraction)

Read more about Interface and Abstract class in the previous section.

Difference Between Encapsulation and Abstraction in Java

Abstraction deals with hiding the details and showing the essential things to the user whereas encapsulation bind your data and code together as a single unit.

Encapsulation is not providing full security because we can access private member of the class using reflection API, but in case of Abstraction we can't access static, abstract data member of a class.

In java you can say it takes all your methods, variables and bind them together in a single class.

Abstraction is implemented in Java using interface and abstract class while Encapsulation is implemented using private, package-private and protected access modifier.

Advantages of Data Abstraction in Java

Here we discuss some of its benefits in order to acknowledge its significance. The benefits of data abstraction are given below;

  • Data abstraction increases the reusability of the code by avoiding any chances of redundancy.
  • It increases the readability of the code as it eliminates the possibility of displaying the complex working of the code.
  • With the implementation of classes and objects, comes enhanced security. Since data abstraction is a method of implementing classes and objects any denying access to other classes of accessing the data members and member functions of the base class.
  • It helps the user to write a high-level code.
  • It separates the entire program into code and implementation making it more comprehensible.
  • Helps the user to avoid writing the low level code.
  • Avoids code duplication and increases reusability.
  • Can change internal implementation of class independently without affecting the user.
  • Helps to increase security of an application or program as only important details are provided to the user.

Interface in Java Encapsulation in Java


Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements

Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs