1

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?

Grzegorz Piwowarek
  • 13,172
  • 8
  • 62
  • 93
Shashi
  • 746
  • 10
  • 39

3 Answers3

5

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

4
  • This is a static block which is used for initializing values
  • This block gets executed when the class is initialized
  • The static initializer block is executed whenver the class is initialized and the order of execution is according to their appearance in program.
Prasad Kharkar
  • 13,410
  • 5
  • 37
  • 56
0

javap -private -verbose class will show you the constant pool and the details of the method bytecode.

Raji
  • 527
  • 3
  • 6