Explore Courses
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Birla Institute of Management Technology Birla Institute of Management Technology Post Graduate Diploma in Management (BIMTECH)
  • 24 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Popular
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science & AI (Executive)
  • 12 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
University of MarylandIIIT BangalorePost Graduate Certificate in Data Science & AI (Executive)
  • 8-8.5 Months
upGradupGradData Science Bootcamp with AI
  • 6 months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
OP Jindal Global UniversityOP Jindal Global UniversityMaster of Design in User Experience Design
  • 12 Months
Popular
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Rushford, GenevaRushford Business SchoolDBA Doctorate in Technology (Computer Science)
  • 36 Months
IIIT BangaloreIIIT BangaloreCloud Computing and DevOps Program (Executive)
  • 8 Months
New
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Popular
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
Golden Gate University Golden Gate University Doctor of Business Administration in Digital Leadership
  • 36 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
Popular
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
Bestseller
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
IIIT BangaloreIIIT BangalorePost Graduate Certificate in Machine Learning & Deep Learning (Executive)
  • 8 Months
Bestseller
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in AI and Emerging Technologies (Blended Learning Program)
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
ESGCI, ParisESGCI, ParisDoctorate of Business Administration (DBA) from ESGCI, Paris
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration From Golden Gate University, San Francisco
  • 36 Months
Rushford Business SchoolRushford Business SchoolDoctor of Business Administration from Rushford Business School, Switzerland)
  • 36 Months
Edgewood CollegeEdgewood CollegeDoctorate of Business Administration from Edgewood College
  • 24 Months
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with Concentration in Generative AI
  • 36 Months
Golden Gate University Golden Gate University DBA in Digital Leadership from Golden Gate University, San Francisco
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Deakin Business School and Institute of Management Technology, GhaziabadDeakin Business School and IMT, GhaziabadMBA (Master of Business Administration)
  • 12 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science (Executive)
  • 12 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityO.P.Jindal Global University
  • 12 Months
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (AI/ML)
  • 36 Months
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDBA Specialisation in AI & ML
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
New
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGrad KnowledgeHutupGrad KnowledgeHutAzure Administrator Certification (AZ-104)
  • 24 Hours
KnowledgeHut upGradKnowledgeHut upGradAWS Cloud Practioner Essentials Certification
  • 1 Week
KnowledgeHut upGradKnowledgeHut upGradAzure Data Engineering Training (DP-203)
  • 1 Week
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
Loyola Institute of Business Administration (LIBA)Loyola Institute of Business Administration (LIBA)Executive PG Programme in Human Resource Management
  • 11 Months
Popular
Goa Institute of ManagementGoa Institute of ManagementExecutive PG Program in Healthcare Management
  • 11 Months
IMT GhaziabadIMT GhaziabadAdvanced General Management Program
  • 11 Months
Golden Gate UniversityGolden Gate UniversityProfessional Certificate in Global Business Management
  • 6-8 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
IU, GermanyIU, GermanyMaster of Business Administration (90 ECTS)
  • 18 Months
Bestseller
IU, GermanyIU, GermanyMaster in International Management (120 ECTS)
  • 24 Months
Popular
IU, GermanyIU, GermanyB.Sc. Computer Science (180 ECTS)
  • 36 Months
Clark UniversityClark UniversityMaster of Business Administration
  • 23 Months
New
Golden Gate UniversityGolden Gate UniversityMaster of Business Administration
  • 20 Months
Clark University, USClark University, USMS in Project Management
  • 20 Months
New
Edgewood CollegeEdgewood CollegeMaster of Business Administration
  • 23 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 5 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
upGradupGradDigital Marketing Accelerator Program
  • 05 Months

Learn Data Abstraction in Java

Updated on 17 November, 2022

5.52K+ views
8 min read

The concept of data abstraction can be explained through a real-life example. Let us consider an example where a driver riding a vehicle knows that applying brakes will stop the vehicle from moving further. So the only information the driver knows is that he has to stop his vehicle from moving, so he applies the brakes. But he doesn’t know the underlying mechanism as to how the vehicle stops when a brake is applied. So this concept can be compared to the data abstraction concept where only the information required to be known to the user is displayed. The underlying information is kept hidden. So, this is the concept of abstraction, and when it is applied in the data, it is known as data abstraction.

Object-Oriented Programming provides ways for utilizing the data abstraction concept. Java is one of Object-Oriented Programming, follows the feature of data abstraction. In these programming languages, abstract classes and interfaces are used for achieving data abstraction.

Check out our free courses to get an edge over the competition

The process of data abstraction in Java is achieved through the class’s abstract classes. Interfaces are also used for data abstraction apart from abstract classes. The keyword “abstract” is used as a non-access modifier for the methods and classes. When defined with the keyword access, a class is an abstract class where the creation of objects is not allowed. Accession of the abstract class is only possible if it is inherited from another class. Abstract methods are those methods that can be used only in abstract classes. These methods don’t have a method body. 

The subclass generally provides the body. Abstract classes can contain methods that are both regular and abstract.

Differences between an abstract class and an abstract method 

The differences between an abstract class and an abstract method are:

1. The abstract classes are those classes that are declared with the keyword abstract.

2. An abstract method is such a type of method which gets declared without its implementation.

3. An abstract class doesn’t need to have all the abstract method methods within itself. It can also contain methods that are not abstract.

4. Whenever a method is defined as an abstract method, it should also be defined again in the subclass. This will make the overriding compulsory and also make the subclass abstract.

5. If any class contains any abstract methods, whether one abstract method or more than that, it should be declared abstract by using the keyword abstract.

6. An abstract class cannot contain any object. A new operator cannot be used to instantiate the abstract class.

7. There is always the presence of default constructors in an abstract class. Also, parameterized constructors can be present in an abstract class.

Check out upGrad’s Advanced Certification in Cloud Computing 

Java Abstract class

The programming language Java implements abstraction through abstract classes. An abstract class may be defined as that class that is declared with the keyword “abstract” with a special instruction that these classes cannot get instantiated. These classes may contain or may not contain abstract methods. 

The above code is taken from https://www.softwaretestinghelp.com/what-is-abstraction-in-java/.

Check out upGrad’s Advanced Certification in Cyber Security

In the above syntax, it can be observed that both the abstract and the non-abstract methods can be contained within an abstract class. Also, the keyword “abstract” is placed before the declaration of the class. 

Read more about the java abstract class here 

Java Abstract Method

Java abstract methods are those methods that are preceded by the keyword “abstract,” but there is no implementation of the methods. The Java abstract methods are declared within the Java abstract class.

Because of the abstract methods, the Java abstract class becomes incomplete because the methods cannot be implemented. Therefore, the inclusion of an abstract form in the abstract class naturally makes the abstract class incomplete.

Its implementation in the subclass can use the abstract method. This subclass will inherit the abstract class and will carry out the implementation of the abstract methods. The general syntax of the abstract method is 

abstract void methodName (parameter_list);

Few rules should be noted while writing the method of abstract

  • If a class contains more than one abstract method, then the class will become an abstract class.
  • There should not be any keywords other than “abstract” while defining the abstract class and methods.

Considering the above points, the following possibilities are not allowed in Java.

  • final
  • abstract native
  • abstract static
  • abstract private
  • abstract synchronized
  • abstract strictfp 

An example of data abstraction in Java is shown below.

https://www.javatpoint.com/how-to-achieve-abstraction-in-java.

The above code is taken from https://www.softwaretestinghelp.com/what-is-abstraction-in-java/.

In the code shown above, there is a class Bank. There is an abstract method within the Bank class which is getInterestRate(). Two other classes BOI and ICICI, are declared, which inherit the class Bank. These declared classes inherit the Bank class and therefore implement the method getInterestRate() returning the interest rates. 

An object of the Bank is created in the primary method. The object of the Bank consists of an ICICI class object which displays the interest rate. In the next step, the object of the class BOI is created too, which displays the interest rate. 

upGrad’s Exclusive Software Development Webinar for you –

SAAS Business – What is So Different?

Data abstraction through the interface

Interfaces are similar to the Java classes, with the only difference being that there are empty methods in an interface. It can also be defined as classes that consist of abstract methods and static constants. Every method present in the interface is public, and it does not contain any constructor. The interface is used for achieving data abstraction, and also it is used for performing multiple inheritances in Java. 

A few features of interfaces in Java are:

  • The interfaces can be used for achieving total abstraction.
  • A single class can use multiple interfaces that lead to the achievement of multiple interfaces.
  • Interfaces allow achieving loose coupling.

The syntax of the interface is shown below:

The above syntax is used from https://www.javatpoint.com/how-to-achieve-abstraction-in-java.

An interface can be used through the keyword “implements.”

A few differences between the abstract classes and the interface are:

  • Both the abstract and also the non-abstract methods can be contained within the abstract classes. While, in an interface, only the abstract methods can be present.
  • Final variables may or may not be present in the abstract classes. In interfaces, the variables can be final as default variables.
  • The class abstract can have variables that are non-final, final, non-static, or static. While, in an interface, only static and final variables may be present.
  • The abstract class allows the implementation of interfaces. An abstract class cannot be implemented in an interface.
  • The inheritance of an abstract class is done through the keyword “extends.” Implementation of the interface is done through the keyword “implements.”
  • The abstract class can implement multiple interfaces, or other classes can be extended by the abstract class. Whereas an interface can allow implementation of only another interface.
  • Apart from public members, both data members that are protected and private are contained in an abstract class. Whereas the members of an interface are by default public. 

Learn Software Courses online  from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs, or Masters Programs to fast-track your career.

Conclusion

The article has described the concepts of data abstraction and has listed how data abstraction can be achieved in Java. For getting more experience in the Java programming language, you can check the Software Development Course offered by upGrad. The course is designed for working professionals and will train you with industry-oriented projects that will develop the required programming skills. More information can be retrieved through our website. For any information and help, our team of assistance can be contacted.

Frequently Asked Questions (FAQs)

1. What is Data Abstraction?

Data abstraction is a software design concept. The problem it solves is to create data structures and functions which are independent of the data types they operate on. It isolates the code from data types and allows the same code to be used in multiple situations. Data abstraction is achieved when the data that is represented by the data structure and the operations that can be applied to them are clearly defined. Abstraction is vital in software development. It is one of the fundamental forces that lead to simpler, smaller and more reliable software. Data abstraction is a vital component of high-level languages.

2. How to achieve abstraction in Java?

Abstractions in java are done using Interfaces. To implement the interface, one needs to provide the implementation as well. Actually, there is no need of inheriting classes to implement the interface. Interfaces are just like any other class in java. What makes them different is the fact that they only have one method.

RELATED PROGRAMS