Implementation of stacks and linked lists in Java