I prefer the first style. There is a caveat that it creates an instance the first time the class is referenced, whether you really meant to get a instance or not, but this has never (yet) been an important thing to me.
This bit:
is not
thread safe. That means two threads calling this code at the same time might get two different instances, which is not what you want. Attempts to make it thread safe with synchronized blocks are common in older references - even Sun's - but they flat don't work. Synchronize the whole method to make it safe.
Tony's point, boiled down, is that you can't reliably force one instance per JVM with this code. Instead you'll get one instance per ClassLoader. Simple standalone apps work fine with a single ClassLoader for all the application code, but many frameworks and containers like
Servlet and
EJB containers have complex families of ClassLoaders. If it's mission critical to really have only one instance in those environments, things get pretty tricky.