Implementation of tree in java