Abstraction in Java

Google Advertisements

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

Google Advertisements

We have more than 5 Groups which have 500000+ Members and some Pages have more than 100000+ members. If you want to post your article on our website/FB Group/FB Page please contact on hitesh.xc@gmail.com or 8076671483

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

Path variable is set for providing path for all Java tools like java, javac, javap, javah, jar, appletviewer which are used in java programming. All these tools are available in bin folders so we set path upto bin folders. Difference between path and classpath in Java

Classpath variable is set for providing a path for predefined Java classes which is used in our application. All classes are available in lib/rt.jar so we set classpath upto lib/rt.jar. Difference between path and classpath in Java

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user. Cloud Computing Tutorial

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects. Download Java C C++ Projects

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: hitesh.xc@gmail.com or 8076671483 Try this Keyword C++ Programs