factory as singleton
Hi,
I have one question in implementing a factory as singleton.
case 1 implementaion:
public class TestFactory{
public static TestFactory factory = new TestFactory();
private TestFactory()
{
// do something...if there is a need
}
public Hi createSomething()
{}
}
case 2 implementation :
public class TestFactory{
private static TestFactory factory = null;
private TestFactory()
{
// do something...if there is a need
}
public static TestFactory getInstance()
{
if (factory == null)
factory = new TestFactory();
return factory;
}
public Hi createSomething()
{}
}
so here is my question.. what is the difference between the two implemenations..
Are they two are the same, but just representing differently..or is there is any difference.. If there is,How should I decide which one to implement? what are the effects?
As I knew jvm takes some time to initialize the static fields. So if we use the static fields before it is initialized we might get some problems.So in my openion case2 is better than case1.am I right?
thanks in advance,

