Meaningless Drivel is fun!*
The moose likes OO, Patterns, UML and Refactoring and the fly likes static methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "static methods" Watch "static methods" New topic
Author

static methods

siva prakash
Ranch Hand

Joined: Aug 24, 2004
Posts: 80
Hi,

when we declare methods as static. does static methods occupy more memory than normal methods.



With Regards,
Siva
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
when we declare methods as static

to call a static method you dont need to instantiate an object, just use ClassName dot MethodName

MyClass.myStaticMethod()


java amateur
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1006
    
    3
Originally posted by siva prakash:
does static methods occupy more memory than normal methods.


No.
Gerald Davis
Ranch Hand

Joined: May 15, 2002
Posts: 872
If have an intention in do Procedural Programming you could come across more performance an memory hits then using objects. Static methods uses stack (call by value) objects us heap(call by reference).

I do know that I recursive use of static method or function can eat up memory , unless the compiler is optimized for it .
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 860
Design considerations are much more important when deciding between static, and instance methods. Why do you ask the question? Even, if there is a difference in memory usage between the two approaches I suspect it is minimal and you will find better ways to optimize memory in other ways.


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
siva prakash
Ranch Hand

Joined: Aug 24, 2004
Posts: 80
Hi all,

thanks for ur replies, can u give me a brief about situationswhere we go for static methods.





With Regards,
Siva
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
if you look at API, you'l find some classes that uses static methods along with non static ones: Color class, for example

Math class has all methods declared static
 
Consider Paul's rocket mass heater.
 
subject: static methods
 
Similar Threads
Static methods can be overridden by static methods only?
static and non-static synchronized methods
method overriding
Inheritance of all members
What is the logic behind calls like JOptionPane.method()