• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

instance methods

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A very basic question:
Instance variables are unique to an instance of a class. However there is nothing unique about the method of a class. So I would think each instance of a class would look up for the instance method in a common memory address. Is that right ?
How are instance methods loaded(?) in memory ?
[ January 17, 2004: Message edited by: Madhavi Mullagiri ]
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to the Intermediate forum...
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer to your first question is yes, there is only one copy of the code for an instance method (or for any method,) which is "shared" by all the instances of that class.
The answer to your second question is "it depends" or, perhaps more appropriately, "it doesn't matter." The precise details of code storage and method lookup will vary by JVM implementation, by platform, even by JVM version; these details may be especially complex when a JIT or the HotSpot engine are in use, as there may be bytecode, native code, and optimized native code versions of any one method.
If you're interested, the source code for Sun's JVMs is available, and there are open-source JVMs like Kaffe you could look at as well. But really, you shouldn't care unless you're planning on implementing your own JVM.
 
reply
    Bookmark Topic Watch Topic
  • New Topic