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

  • Home
  • SEARCH
  • 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 5967647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:58:27+00:00 2026-05-22T19:58:27+00:00

I know this topic has been discussed and killed over and over again, but

  • 0

I know this topic has been discussed and killed over and over again, but I still had one doubt which I was hoping someone could help me with or guide me to a pre-existing post on SO.

In traditional C, static variables are stored in data segments and local variables are stored in the stack. Which I would assume will make static variables more expensive to store and maintain when compared to local variables. Right?

When trying to understand in terms of Java or C#, would this be dis-advantage for static classes when compared to singleton class? Since the entire class is loaded into memory before class initialization, I don’t see how it can be an advantage unless we have small inline-able functions.

I love Singleton classes, and would hate to see it become an anti-pattern, I am still looking for all the advantages that come with it…and then loose to the argument of thread-safety among others.

-Ivar

  • 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-22T19:58:28+00:00Added an answer on May 22, 2026 at 7:58 pm

    Different from C, the static keyword in Java class definition merely means, This is just a normal class like any other class, but it just happens to be declared inside another class to organize the code. In other words, there is no behavioral difference whatsoever between the following 2 way of declaration*:
    a)

    class SomeOtherClass {
        static class Me {
            // If you "upgrade" me to a top-level class....
        }
    }
    

    b)

    class Me {
        // I won't behave any different....
    }
    

    Class definitions are loaded to memory when the class is used for the first time, and this is true for both “static” and “non-static” classes. There are no difference in how memory will be used, either. In older JVMs, objects were always stored in heap. Modern JVMs do allocate objects on stack when that is possible and beneficial, but this optimization is transparent to the coder (it is not possible to influence this behavior via code), and use of the static keyword does not have any effect on this behavior.

    Now, back to your original question, as we have seen we really can’t compare static classes and Singleton in Java as they are completely different concept in Java (I’m also not sure how static classes would compare with Singleton, but I will focus on Java in this answer). The static keyword in Java is overloaded and has many meanings, so it can be confusing.

    Is Singleton automatically an “anti-pattern”? I don’t think so. Abuse of Singleton is, but the Singleton pattern itself can have many good uses. It just happens to be abused a lot. If you have legitimate reason to use the Singleton pattern, there is nothing wrong in using it.


    *Note: Why write static at all, you might ask. It turns out “non-static” nested classes have their own somewhat complicated memory management implication, and its use is generally discouraged unless you have a good reason (pls refer to other questions for more info).

    class SomeOtherClass {
        Stuff stuff;
        class Me {
            void method(){
                // I can access the instance variables of the outer instance 
                // like this:
                System.out.println(SomeOtherClass.this.stuff);
                // Just avoid using a non-static nested class unless you 
                // understand what its use is!
            }
        }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry, I know that this topic has been covered a bit. I've read the
I hope this isn't too off topic for this forum, but I have been
I know that virtual and static methods are opposing concepts, but I think that
I recently joined this organisation that I am currently working at that has asked
This is one of the strangest errors I've ever seen. I'm doing a very
I know that each programming language has certain guideline and styles. My question is
I know the topic of pass by reference vs. pass by pointer is heavily
Hi I am relatively new to this topic so I have no idea if
This is an easy question but I am not sure the correct jargon to
I've done some quick googling on the topic but couldn't find much information about

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.