code sample from javarecipes.com