Alex Rivera | Logout

What does Static {} mean in the Java Syntax?

Asked 2011-11-10T16:04:53.670
42

I came across this Java code:

static {
    String aux = "value";
    try {
        // some code here
    } catch (Exception e) { }
    String UUID_prefix = aux + ":";
}

I am new to Java, please explain what is happening here.

Edit
Report

1 Answer

7

This is a static initializer block. You must have found it in a class's body outside of any method. The static init block runs only once for each class, at classload time.

answered 2011-11-10T16:06:58.450

Your Answer