Finished Java version.