Solved

Difference why Singelton Class and Static Class

Posted on 2009-04-07
4
484 Views
Last Modified: 2013-11-23
Can anyone tell me the difference between a singleton class and a Static class, as with both mechanism we can create only single instance per of a class.
I would appreciate if someone can explain me the difference with example.

0
Comment
Question by:sunsim24
4 Comments
 
LVL 12

Expert Comment

by:basav_com
ID: 24091856
0
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 24092698
theres really no such thing as a singleton class. A psuedo singleton is mostly implemented using static.

0
 
LVL 4

Expert Comment

by:aman123_123
ID: 24093935
There is nothing as a Static class in Java. You should make your a class singleton when you only want a single instance of the class in your application.
Also , you should make a class singleton when you do not want to maintain the state of its instances. For example, every object of the following class will have a different state.

class Point {
int x,
int y
}

However, if you have a class whose state is not be maintained, then you should make it singleton. For example

class PointUtil {
public Point isAbove(Point a, Point b) (...);
public Point isOnRight(Point a, Point b) (...);
}

Such classes you should make singleton, as two instances of this function will be of no use.

You can also achieve the same by having all functions as static but static functions are loaded at startup , so you are better off making it a singleton.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now