Added sample Java code from SO answer