Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6973993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:10:48+00:00 2026-05-27T17:10:48+00:00

It was already asked what’s the difference between singleton and static class. However, knowing

  • 0

It was already asked what’s the difference between singleton and static class. However, knowing the difference, I still feel confused every time I need to chose.

So for myself I defined two different cases – I’m using singletones mainly for POJO classes(in java) if there should be only one instance of this class(which is very rarely) and static classes for all service classes(which occur very often).

For example, in my application I need to store messages(I have a serializable class Message), write them into a file, read from a file and access during the runtime. I don’t see any reason to use singleton here, static class is just okay. The only static class is MessageStorage which has 3 functions – read, write and getMessages and also one static private arraylist of messages.

Is this approach reasonable and if not, what’s its problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:10:48+00:00Added an answer on May 27, 2026 at 5:10 pm

    The two main reasons for using a “singleton” in Java are:

    1) So some storage can be associated with an otherwise “static” class.

    2) Where you may have multiple “singletons” for different subclasses (or interface implementations) of a given service, and the singleton is passed as a way of identifying which specific service to employ.

    Of course, instead of #1 you can use static fields of a “static” class to contain the data, but it’s often more convenient (and, in many cases, more efficient) to have a single instance of the subject class to contain the data, vs multiple static members which are instances of other classes.

    And, re #2, there are a number of cases in the JDK of a single class implementing, in effect, multiple “singletons”, in the guise of defining “constants”. (Eg, java.awt.font.TextAttribute.)

    In general, the motivation to have singletons is less in Java than in C-based languages, since Java does implement true class-associated (and class-protected) static data, vs the vaguely disguised (if disguised at all) global statics used in the C languages, and so one can simply have multiple static fields in a class vs the need to have a “central” object to contain the fields in the C languages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I already asked here with no luck, but feel free to read it: http://groups.google.com/group/jquery-en/browse_thread/thread/fdf7a584b30d4bb9
I have already asked this question on ServerFault however I got very minimal replies....one
I already asked a separate question on how to create time triggered event in
I already asked this question, but in a way that confused people. So what
I already asked this question and I got additional question about using class I
I already asked a more general question, with a great answer. However, I want
I already asked similar question here, but I still get some errors, so I
some time ago someone already asked this question and a few answers were given
I already asked this question at the JOS-.NET board but Joel is closing that
I already asked a similar question, PE Header requirements , but I'm not really

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.