Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Java `static {}` keyword all by itself? [duplicate]

Tags:

java

static

Possible Duplicate:
Static Block in Java

I came across the following use of static and did not figure out what it does. I am aware of using for example static String hello = "World"; but I do not understand the following.

static {
   loadFromProperties(new Properties());
}
like image 738
dokaspar Avatar asked Dec 21 '22 18:12

dokaspar


1 Answers

It's called a static initializer. It's a block of code that runs when the class is initialized.

Related question (probably a dup actually):

  • Static Block in Java
like image 108
aioobe Avatar answered Dec 23 '22 09:12

aioobe