View RSS Feed

Design Patterns

Design patterns in Java.

  1. Early instantiation using implementation with static field

    by , 03-09-2012 at 06:48 PM
    The singleton object gets instantiated in case the class gets loaded & is not when it is used first, in the given implementation. This happens because the instance member has been declared static. Thatís why there is no need of synchronization of any part of the code, in such cases. Class gets loaded once when the uniquity of the object is guaranteed.
    Java Code:
    //Early instantiation using implementation with static field.
    class Singleton
    {
    	private static Singleton
    ...