This bit declares a static field:
private static Map<String,Object> countries;
So it's accessible directly on the class, e.g. LanguageBean.countries
(or just countries
), but only from code within the class, because it's private.
This bit is a static initializer:
static{
countries = new LinkedHashMap<String,Object>();
countries.put("English", Locale.ENGLISH); //label, value
countries.put("Chinese", Locale.SIMPLIFIED_CHINESE);
}
That runs when the class is loaded, before any instances are created, and does indeed add some entries to countries
. If there are multiple static initializers, they're run in source code order. See Static Initializer Blocks in this tutorial.
FWIW, there are also per-instance versions of both of those. An instance field:
private int foo;
...and an instance initializer; they look a bit weird, because they're just blocks with nothing in front of the block:
{
this.foo = 42;
}
In context, and with a second instance member:
class Thing {
private int bar = 16; // An initializer on the declaration
private int foo;
// An instance initializer block
{
this.foo = 42; // Or just foo = 42;, but I prefer to be clear
}
}
So you can do the same sort of thing for instances.