adding java solution for #18