Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Difference why Singelton Class and Static Class

Posted on 2009-04-07
4
Medium Priority
?
511 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
3 Comments
 
LVL 12

Expert Comment

by:basav_com
ID: 24091856
0
 
LVL 92

Accepted Solution

by:
objects earned 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

783 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