Implementation of data structures in java