• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Static Method Vs Single Ton class method

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a scenario like this.
I am in Class A and i want to call one method which is there in another class(Class B). I identified i have number of requests to Class A(here class A is my Servlet). So, now i am changing Class B to Single Ton for every request that is coming from Class A to avoid multiple objects creation for every request. Mean while i have an another idea to change method in class B as static.

Basically my question is there any difference to make object as SingleTon and call method Vs directly declare method as Static and call that method directly with class name.

Please help me to understand this concept clear to me.


Thanks
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

jami siva wrote:Basically my question is there any difference to make object as SingleTon and call method Vs directly declare method as Static and call that method directly with class name.


Not a great deal, especially if your method doesn't rely on a lot of object state. Basically, singletons (and it's 'singleton', not 'Single Ton') are kind of frowned on these days.

However, without knowing a bit more about what this method does, it's hard to advise precisely.

Winston
 
jami siva
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Still I was not understand where we use Singleton. Same thing we can achieve by using static method with in the class.
Again one interviewer asked me same question.


Thanks,
reply
    Bookmark Topic Watch Topic
  • New Topic