some algorithm implementation in java