My java implemention