What does Static {} mean in the Java Syntax?

This is a static initialization block. Think of it like a static version of the constructor. Constructors are run when the class is instantiated; static initialization blocks get run when the class gets loaded.

You can use them for something like this (obviously fabricated code):

private static int myInt;

static {
    MyResource myResource = new MyResource();
    myInt = myResource.getIntegerValue();
    myResource.close();
}

See the “Static Initialization Blocks” section of Oracle’s tutorial on initializing fields.

Leave a Comment