Search code examples
javastaticblockjavap

What are static code blocks for?


I want to ask what javap shows besides the public fields and methods of the classes passed to it.

I was reviewing a class file having only a static variable. As expected, javap shows the static variable and class constructor as output but it also shows something like:

static {};

What does this line mean?


Solution

  • static code block initializes the static variables in the program. it gets executed when the class is initiated, even before constructor call.