INITIALIZING STATIC VARIABLES It's a common strategy to create static fields to enable easy access to variables from other classes without having to instantiate the class that contains those values or objects. Beginning developers often choose to add a new initialization method to the class and make sure the method is called as part of their application's startup method, but this approach prevents the class from being self-contained. There are two common approaches to this problem: static initializers and lazy instantiation. Lazy instantiation refers to the method of avoiding instantiating a variable until it is actually needed. It requires the use of get methods to detect when initialization is required. Here's an example: public class lazyTest { private static String myString = null; static String getMyString() { if(myString == null) { myString = "initialized value"; //do all initialization here } return myString; } } In a multithreaded environment, the getMyString() method should be synchronized. Static initialization takes advantage of a Java idiom that allows code to be run the first time a class is loaded. Static initializers are interesting for two reasons: because they are the only way to run code outside of a declared method and because they are guaranteed to be run no more than once within a single class loader. Since the code is not run until needed, it also qualifies as a form of lazy instantiation. Here is a simple example: public class initTest { public static Calendar initDate = null; //static initializer { initDate = Calendar.getInstance(); } } The most important restriction of static initializers is to never, ever throw an uncaught exception because doing so will cause the class loading process to fail and make the entire class object and all of its methods and fields inaccessible. The primary difference between the two methods is that lazy initialization allows delaying initialization on a per-variable basis, while static initializers only work on a class level. Either approach can help keep your classes self-contained. -------------------------------------------