• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Where the Static variables are stored?

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can some body help me to answer my two Queries?
1) Where the Static variables and methods are actually stored?
2) Is a JDK can have more than one JVM.

Thanks:
Sagar
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this may belong more to Java Beginner/Intermediate than here...

About the first one, static vars are stored in fixed memory locations and prior to object creation. That's why you can use them without instantiating any objects, like with Math.PI. Remember there's one and only one static var shared among all objects, it belongs to the class, no to its instances.

About the second one, I'm not sure.
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Where the Static variables and methods are actually stored?

In java, there is a class loader which loads classes into memory as objects. These objects can then be used to create instance objects like when you call new Object(). Going back to the class loader, it initializes any static fields and all methods(?) which are stored along with the class descriptor. When you go myObject.getClass(), you are seeing a view into this class object.

2) Is a JDK can have more than one JVM.
You can have multiple instances of a JVM on a pc at any time. It happens often if you see it happening or not. Not only that, you can have multiple class loaders running in a single JVM with multiple instances of the same classes. Beware though, the number of uses for multiple class loaders is low, and they are very difficult to master. If you're interested, I found http://www.onjava.com/pub/a/onjava/2003/11/12/classloader.html
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic