algo impl by Java