Initializers are blocks of code that are executed when a class or an instance of a class is created. There are two kinds of initializers, ''static initializers'' and ''instance initializers''.
The purpose of staticStatic initializers is to initialize static fields when the class is created. They are declared using the <code>static</code> keyword:
<source lang=Java5>
Line 1,058 ⟶ 1,059:
</source>
AnyA class is created only once. Therefore, therefore static initializers aren'tare not called more than once. On the contrary, instance initializers are automatically called before the call to a constructor every time an instance of the class is created. Unlike constructors instance initializers can'tcannot take any arguments and generally they can'tcannot throw any [[Exception handling#Checked exceptions|checked exceptions]] (except in several special cases). Instance initializers are declared in a block without any keywords:
<source lang=Java5>
Line 1,068 ⟶ 1,069:
</source>
Since Java has a garbage collection mechanism, there are no [[Destructor (computer science)|destructors]]. However, every object has a <code>finalize()</code> method called prior to garbage collection, which couldcan be overridden to implement finalization.