Question
What is the difference between a Singleton pattern and a static class in Java?
How is a singleton different from a class filled with only static fields?
Question
How is a singleton different from a class filled with only static fields?
Solution
Almost every time I write a static class, I end up wishing I had implemented it as a non-static class. Consider:
Because of these two points, non-static classes make it possible to write more reliable unit tests for items that depend on them, among other things.
A singleton pattern is only a half-step away from static classes, however. You sort of get these benefits, but if you are accessing them directly within other classes via `ClassName.Instance', you're creating an obstacle to accessing these benefits. Like ph0enix pointed out, you're much better off using a dependency injection pattern. That way, a DI framework can be told that a particular class is (or is not) a singleton. You get all the benefits of mocking, unit testing, polymorphism, and a lot more flexibility.
Solution
Let me sum up :)
The essential difference is: The existence form of a singleton is an object, static is not. This conduced the following things:
Last but not least, whenever you are going to implement a singleton, please consider to redesign your idea to not use this God object (believe me, you will tend to put all the "interesting" stuff in this class) and use a normal class named "Context" or something like that instead.