jQuery in Action, 2nd edition*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "residence of static variable" Watch "residence of static variable" New topic
Author

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
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi,

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: 14074
    
  16

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 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: residence of static variable
 
Similar Threads
Static variable
about protected n static
Fix an infity loop
Best Practice for getters and setters
Dont declare global variables in Servlet