Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Difference why Singelton Class and Static Class

Posted on 2009-04-07
4
Medium Priority
?
506 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 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

Independent Software Vendors: 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…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

661 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