Improved java example.