Java algorithms implementation