Introduction
This chapter explores abstraction and how it applies to algorithms, classes, and data structures. Abstraction enables Java generics, which allows us to reuse code that would be essentially the same, save for the exact data type being used or stored. Several Java data structures are explored, including Queues and Stacks.
Learning Objectives
- Explain polymorphism as it is implemented in the Java Programming language
- Introduce the comparable Interface
- Describe the differences between an Interface and Abstract class
By the end of this chapter, you should be able to answer the following questions:
- What is the purpose of abstraction?
- How does abstraction support Object Oriented Programming?
- Under what circumstances is it better to use an abstract class over an interface?
- Under what circumstances is it better to use an interface over an abstract class?
Abstraction refers, in general, to the idea of providing a simplified or higher level interface to a complex system. It is closely related to the idea of a "black box." Abstraction makes it possible to understand or use a system, while ignoring some of the details of what actually goes on in the system. Control abstractions make it possible to implement algorithms on a higher level than machine language. Abstraction is a fundamental concept in computer science.
Writing code that will work with various types of data, rather than with just a single type of data. The Java Collection Framework, and classes that use similar techniques, are examples of generic programming in Java.
A data structure consisting of a list of items, where items can only be added at one end and removed at the opposite end of the list.
A data structure consisting of a list of items where items can only be added and removed at one end of the list, which is known as the "top" of the stack. Adding an item to a stack is called "pushing," and removing an item is called "popping." The term stack also refers to the stack of activation records that is used to implement subroutine calls.