Win a flower (🌹) or copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java (📚) this week in the Agile and Other Processes 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

static methods

 
pioneer
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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



With Regards,
Siva
 
pioneer
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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()
 
Master Rancher
Posts: 1195
22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by siva prakash:
does static methods occupy more memory than normal methods.



No.
 
pioneer
Posts: 872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
pioneer
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
siva prakash
pioneer
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

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





With Regards,
Siva
 
miguel lisboa
pioneer
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Note to self: don't get into a fist fight with a cactus. Command this tiny ad to do it:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!