Several algorithm implementation in JAVA