java solution