File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes residence of static variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "residence of static variable" Watch "residence of static variable" New topic

residence of static variable

krishna prasad gunasekaran
Ranch Hand

Joined: Jul 25, 2006
Posts: 158
where do the static variables live in heap? inside instance variable or somewhere else?

have a great day,
krishna prasad
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24195


Welcome to JavaRanch!

The Java VM specification doesn't say specifically, so they could be anywhere. Why does it matter to you?

[Jess in Action][AskingGoodQuestions]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15042

Certainly not inside an instance variable. The thing you need to remember is this:

For static member variables, there is only 1 copy of the variable for the whole class. All instances of the class share the same variable.

For non-static (= instance) member variables, there is 1 copy of the variable for every instance of the class. Each instance has its own copy of the variable.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: residence of static variable
It's not a secret anymore!