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 987859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:32:58+00:00 2026-05-16T05:32:58+00:00

I had an interview recently and he asked me about Singleton Design Patterns about

  • 0

I had an interview recently and he asked me about Singleton Design Patterns about how are they implemented and I told him that using static variables and static methods we can implement Singleton Design Patterns.

He seems to be half satisfied with the answer but I want to know

  1. How many different ways we can
    implement Singleton Design Pattern
    in Java ?
  2. What is the scope of Singleton Object and how does it actually work inside JVM ? I know we would always have one instance of Singleton Object but what is the actual scope of that object, is it in JVM or if there are multiple application running than it’s scope is per context basis inside the JVM, I was really stumped at this and was unable to give satisfying explanation ?
  3. Lastly he asked if it is possible to used Singleton Object with Clusters with explanation and is there any way to have Spring not implement Singleton Design Pattern when we make a call to Bean Factory to get the objects ?

Any inputs would be highly appreciated about Singleton and what are the main things to keep in mind while dealing with Singletons ?

Thanks.

  • 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-16T05:33:00+00:00Added an answer on May 16, 2026 at 5:33 am

    There are a few ways to implement a Singleton pattern in Java:

    // private constructor, public static instance
    // usage: Blah.INSTANCE.someMethod();
    public class Blah {
        public static final Blah INSTANCE = new Blah();
        private Blah() {
        }
        // public methods
    }
    
    // private constructor, public instance method
    // usage: Woo.getInstance().someMethod();
    public class Woo {
        private static final Woo INSTANCE = new Woo();
        private Woo() {
        }
        public static Woo getInstance() {
            return INSTANCE;
        }
        // public methods
    }
    
    // Java5+ single element enumeration (preferred approach)
    // usage: Zing.INSTANCE.someMethod();
    public enum Zing {
        INSTANCE;
        // public methods
    }
    

    Given the examples above, you will have a single instance per classloader.

    Regarding using a singleton in a cluster…I’m not sure what the definition of “using” is…is the interviewer implying that a single instance is created across the cluster? I’m not sure if that makes a whole lot of sense…?

    Lastly, defining a non-singleton object in spring is done simply via the attribute singleton=”false”.

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

Sidebar

Related Questions

This task has already been asked/answered, but I recently had a job interview that
I had an interview question that asked how I would design a system to
I was recently asked in an interview about the parameter for a copy constructor.
I had a C++ interview recently where I was asked, how does the compiler
I had an interview recently where I was asked to produce the traditional FizzBuzz
I had an interview question that asked me for my 'feedback' on a piece
Recently I had a question on the interview - I was asked to compare
I recently had an interview where I was asked to connect to the companies
Recently i had an interview in which the question was asked as How would
In an interview they had asked an Question like this there are three overloading

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.