add java algorithm implementation