I want to know where static variables are stored in Java.
There are already few questions on SO, like:
where is a static method and a static variable stored in java. In heap or in stack memory
The link states that static variables are stored on the heap.
But following is an en excerpt from a book by Bill Veners ("Inside the Java Virtual Machine"):
The Method Area
Inside a Java Virtual Machine instance, information about loaded types is stored in a logical area of memory called the method area. When the Java Virtual Machine loads a type, it uses a class loader to locate the appropriate class file. The class loader reads in the class file--a linear stream of binary data-- and passes it to the virtual machine. The virtual machine extracts information about the type from the binary data and stores the information in the method area. Memory for class (static) variables declared in the class is also taken from the method area.
It clearly states that when a class is loaded, static variables are stored in the method area. The method area is different from the heap as far as I know. So the book is in contradiction with the provided SO link.
Can someone please clarify the confusion?