The construct marks the interface as generic. We declare the six methods I just mentioned before. The interface specifies which methods have to be implemented inside the stack class. Let’s start with the interface for our stack. isEmpty (to check whether the stack is empty).It should provide the following six methods: The class is generic in order to store different data types. Stack Data Structure in Java push(): This method is used for inserting an element pop(): This method is used for removing an element peek(): The peek(). Today, we try to recreate this data structure in Java with our own generic class and interface. The usual push and pop operations are provided, as well as a method to peek at the top item on the stack, a method to test for whether the stack is empty, and a method to search the stack for an item and discover how far it is from the top. The Stack class represents a last-in-first-out (LIFO) stack of objects. It behaves like a data container where new items are added to the top of the stack and you only have access to last one added (most top item). A stack is a fundamental data structure in programming.