Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Difference between in making a class as singletone and

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between in making a class as singletone and
making a class with all the methods as its static method?

In which situations we will use which method.

First Method.

public final class Singleton{

private static final Singleton singleton = new Singleton();


private Singleton(){

System.out.println("Singleton Object Created:");
}


public static Singleton getInstance(){

return singleton;

}

public void getMessage(){
return "Helo ";
}

}

--------------------


Second Option


public class Second{

public static void getMessage(){
return "Helo ";
}
}


Thanks for your help in Advance.
Have a nice day.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A couple recent discussions of the same topic:

https://coderanch.com/t/328733/java/java/static-method-vs-singleton-static
https://coderanch.com/t/381446/java/java/java-singleton-implementation-choices
 
Tina Jain
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have gone through many programming books, but such nice answer was never there.

I cannot thank you enough for giving me such valuable resources.

Thank you for all your help.



Have a Nice Day,
Best Regards,
Tina Jain
[ November 21, 2006: Message edited by: Tina Jain ]
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both are different.
static methods will be shared by the 'N' nubmer of objects.
Client can create only one instance of Singleton class.
 
I miss the old days when I would think up a sinister scheme for world domination and you would show a little emotional support. So just look at this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic