title: In order to access data elsewhere in java, where should I place it?
body: <p>I want to put data which is from a file to a variable, then I can access it elsewhere(in other classes) conveniently. I know the <code>file path</code> and read it to a variable. Then I place it in a Class. The data <strong>won't be changed</strong> and have <strong>only one</strong> copy.</p>
  
  <pre><code>// store data in a static field
  public class MyContainer {
    private static Map&lt;String, MyClass&gt; data;
    public static void setData(Map&lt;String, MyClass&gt; data) {
      this.data = data;
    }
    public static Map&lt;String, MyClass&gt; getData(){
      return data;
    }
  }
  
  // set data at one place
  Map&lt;String, MyClass&gt; data = new HashMap&lt;&gt;();
  MyContainer.setData(data);
  
  // access data at other places
  MyContainer.getData(data);
  </code></pre>
  
  <p>Though the code above can achieve this, I think <strong>it's bad</strong> because I could access it before assigning data to it.<br>
  How to implement this correctly?</p>