algorithm of java