Muhammad Ali Khojaye wrote:use a static initializer so our "instance" will be initialized only when it is first accessed.
1) That does not compile; you can't give a final field a value twice (first null, then a Singleton object)
2) This code will be just as efficient as "private final static Singleton instance = new Singleton();". Both will create the variable only when the class is loaded first.
Or you might check if it is initialized in getInstance method.
Ah, the dreaded double checked locking "pattern". Read
this to see why it should not be used in that version.
You also forgot one of the easiest ways:
These days, the locking overhead of using synchronized is not as big of a performance hit as it used to be. It's quote reasonable to use it.