Implementation of a stack and its operations in Java