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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:06:16+00:00 2026-05-15T16:06:16+00:00

I was wondering, whether the following code are safe. public class GUIBundle { //

  • 0

I was wondering, whether the following code are safe.

public class GUIBundle {

    // The technique known as the initialization on demand holder idiom, 
    // is as lazy as possible.
    // http://en.wikipedia.org/wiki/Initialization_on_demand_holder_idiom
    //private static class BundleHolder {
    //    private static final ResourceBundle bundle = ResourceBundle.getBundle("org.yccheok.jstock.data.gui");
    //}
    private static final ResourceBundle bundle = ResourceBundle.getBundle("org.yccheok.jstock.data.gui");

    private GUIBundle() {
    }

    public static String getString(String key) {
        // return BundleHolder.bundle.getString(key);
        return bundle.getString(key);
    }
}

public class SellPortfolioChartJDialog extends javax.swing.JDialog {

    private static final String[] cNames = new String[] {
        GUIBundle.getString("BuyPortfolioTreeTableModel_NetGainValue")
    };
}

Since cNames is within static scope, is it safe for it to access static bundle? Does it make any different whether I am using lazy initialization technique?

I remember I came across an article (I lost the article anyway) talking about nondeterministic of initialization order of static variables. I am not sure whether the nondeterministic of initialization order of static variables, applied to the above case?

  • 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-15T16:06:16+00:00Added an answer on May 15, 2026 at 4:06 pm

    I believe the nondeterministic initialization order of static variables (in different compilation units) is a C/C++ “feature”. In Java, static variables are initialized when their class is loaded, and within a single class in their order of declaration. So the order is deterministic (at least in a single threaded environment).

    This guarantees that what you intend to do should work: when GUIBundle is first referenced, the classloader loads it and initializes bundle too. The call to GUIBundle.getString() happens only after the class initialization is done.

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

Sidebar

Related Questions

I was wondering whether you think the following code usually indicates a bad design
I have the following code (cut down for readability): Main Class: public StartProcess() {
I wondering whether anyone has any good ideas on optimizing the following code. I
I have the following code but it seems to not connect, just wondering whether
I was wondering whether the following can be easily implemented in OpenGL: divide window
Following another question on SO (I am no PHP expert), I am wondering whether
I'm wondering whether or class data members from multiple levels of inheritance are allocated
I'm wondering whether prepared statements in Android (instances of SQLiteStatement) are thread-safe. In particular
I was wondering how to check whether a variable is a class (not an
I am adding the following code to check whether a checkbox should be checked

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.