Java versions of algorithms