Many Java programmers, including my self, might have mistaken that the portion of code that initializes the static variables of a class called the static constructor. Why Not A Java Static Constructor? It is actually not a constructor that initializes the static variables' value. This is because static variables do not need to and can not be constructed as they are being … [Read more...]
Java: Static Variables, Static Methods and Static Constructor
Java's static variables are variables or fields that are common to all object of a class. Unlike instance variables, objects of the same class have their own distinct copies of the variables and values. In other words, a static variable is shared among objects of the same class. You can declare static variables (or static fields or class variables) by adding static modifier to … [Read more...]
Java Static Constructor
Recently I wrote a Java class that maps ISO 3166-1-alpha-2 country code to country name and encountered a static constructor initialization problem. My code is as following: … [Read more...]