Static
The keyword static
means that a member of an object, in this case a field, is not tied to an instance of a class, but is a member of the class in general instead. If the static member is a field, it is initialised during loading of a class.
It is accessible through the class rather than through an instance (though the latter is not impossible, it is considered bad form), so it is accessible without the constructor having ran at all — ever.
Final
The keyword final
, when applied to a field of an object, means that it can be assigned to only once, and that it has to be assigned to during initialisation.
Static Final
Taken together, these two keywords effectively define a constant: it can be assigned to only once, has to be assigned to, and is the same for all instances of that class.
Since the static field is initialised during class loading, it has to be initialised then, either at declaration, or in a static initialiser block.
This means that if and when you reach the constructor, it will already have been initialised, because it needed to already have been initialised.
Singleton
If you're looking for a class member that you only assign to once, but read many times, you're dealing with a singleton. The singleton pattern is commonly used for access to a shared resource.
The field is made static but not final; instead when accessing the field, the code checks whether it has been initialised already, if not, it is done then and there. Note that in environments with multiple threads, you need to synchronise access to the field, to avoid accessing it while it is initialising.