Stack and queue implementation in Java