static initializer

A block marked static inside a class that runs exactly once, the first time the class is actually used.

In more detail

Class initialization is lazy: the JVM runs static setup on first use, not at program start. The course proves this by printing from a static block and seeing the message appear between two other lines. Expensive static setup therefore shows up as a pause in the middle of a request, and a failure in it surfaces late.

Example

static { System.out.println("Heavy is being initialised"); }

Related terms

Taught in

References

Certification courses