Improve java snippet