Added java algorithm implementation.