The boot blocks are executed when an instance is created or when the class is loaded by the JVM. They have no return, name and parameters.
The static boot blocks are executed only when the class is first loaded. Instance initialization blocks run whenever a new instance is created.
Rules, withdrawals on the website Java Naveia:
- instance initialization blocks are executed in the order they appear;
- static startup blocks only run once, when the class is first loaded into the JVM;
- instance initialization blocks run every time a new instance is created and after the method call
super()
within the
builder.
If there are multiple classes in the inheritance tree with multiple blocks
static, all of them will be executed before the instance blocks.
Reference: Java naveia
Related: What is the use of nested blocks in Java?
– user28595
Static blocks, heritage and constructors in Java
– user28595
@diegofmby responses seem to be duplicate even. I hoped they had news not posted before.
– Maniero