Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

methods are loaded before instance live

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Methods are loaded into memory before any instance created, so if you created a static method then this method will just be like any instance method, but the JVM will give you access to it before any instantiation of the object.

therefore the static methods have no effect on memory, its effect on memory just like the effect of access modifier.

Verify this please
Thanks
 
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well it still has _some_ effect on memory, the method and it's stack of instructions still need to be loaded in the JVM.

Heh, Campbell beat me to it with a much better explanation, I'd stick to his
[ November 03, 2008: Message edited by: Martijn Verburg ]
 
Marshal
Posts: 74783
336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't load methods, but the class. Each method lives in the class, as you can see from descriptions of classes (eg the BCEL manual). Each instance method has an additional argument for the location of the object it is called on.
So all the methods are loaded inside the class; instance methods are not accessible until there is an instance to call them on. So all methods are put into memory as soon as the class is mentioned, even if you can't call them until there is an instance.

Static methods, however, are accessible from the name of the class as soon as the class file is loaded, which means as soon as the class name is mentioned in your code.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic