code samples from javarecipes.com