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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)