The static
keyword is used in java mainly for memory management. We may apply static
keyword with variables, methods, blocks and nested class. The static
keyword belongs to the class than instance of the class.
Memory allocation for stactic
variables only happens once when the class is loaded in the memory.
So, here once the class is loaded by the classloader
the memory will be allocated for integer a and stacic block.
Static methods (in fact all methods) as well as static variables are stored in the PermGen section of the heap.
Data that may outlive the call to the procedure that created it is usually allocated on a heap. E.g. new to create objects that may be passed from procedure to procedure.
The size of heap can not be determined at compile time. Referenced only through pointers or references, e.g., dynamic objects in C++, all objects in Java
Names local to a procedure are allocated space on a stack. The size of stack can not be determined at compile time.
Please refer the following tutorial for more about memory management : http://www.oracle.com/technetwork/java/javase/memorymanagement-whitepaper-150215.pdf