java – What is the correct way to have globally accessible class instances?

I’ve been thinking about the way I normally write my code after I started reading “Effective Java” by Joshua Block and I’m wondering what the “best practice” is for doing this… and I think the best way is to just show you how I normally do it.

I start with a class that I just call C and I keep it in a package called constants.

package constants;    
    
public class C {
             
  public enum Options {
    ADD, SUBTRACT, MULTIPLY, DIVIDE
  }
        
  public static ClassA classA;
  public static ClassB classB;
        
  public static Integer abResult;
            
  public static String CSS_BUTTON     = C.class.getResource("Button.css").toExternalForm();
  public static String CSS_TEXT_FIELD = C.class.getResource("TextField.css").toExternalForm();
        
  public static void sleep(long time) {
    try {
      TimeUnit.MILLISECONDS.sleep(time);
    }
    catch (InterruptedException e) {e.printStackTrace();}
  }
}

Then ClassA:

public class ClassA {

  public ClassA() {}

  public ClassA(String propertyA, String propertyB) {
    this.propertyA = propertyA;
    this.propertyB = propertyB;
  }

  private String propertyA;
  private String propertyB;

  public String getPropertyA() {
    return propertyA;
  }

  public String getPropertyB() {
    return propertyB;
  }

  public void setPropertyA(String propertyA) {
    this.propertyA = propertyA;
  }

  public void setPropertyB(String propertyB) {
    this.propertyB = propertyB;
  }
}

Then ClassB:

public class ClassB {

  public ClassB() {}

  public ClassB(Integer valueA, Integer valueB) {
    this.valueA = valueA;
    this.valueB = valueB;
  }

  private Integer valueA;
  private Integer valueB;

  public Integer getPropertyA() {
    return valueA;
  }

  public Integer getPropertyB() {
    return valueB;
  }

  public void setValueA(Integer valueA) {
    this.valueA = valueA;
  }

  public void setValueB(Integer valueB) {
    this.valueB = valueB;
  }

  public Integer getResults() {
    return valueA * valueB;
  }
}

Then from anywhere in the program, I can get to those classes like this:

public Class Work() {

public Work() {}

public Work(String propertyAB, Integer valueAdd, Integer valueSub) {
  this.propertyAB = propertyAB;
  this.valueAdd = valueAdd;
  this.valueSub = valueSub;
}

private String propertyAB;
private String propertyBA;
private Integer valueAdd;
private Integer valueSub;

public void someMethod(C.Options option) {
  C.classB = new ClassB(32, 68);
  if(option == C.Options.ADD) {
    C.abResult = C.classB.getResults() + this.valueAdd;
  }
  else if (option == C.Options.SUBTRACT) {
    C.abResult = C.ClassB.getResults() - this.valueSub;
  }
}

}

Or if I’m working with a lot of threads, I don’t like to constantly write out the try/catch for TimeUnit – sleep function, so I just call it from my constant class.

C.sleep(800);

etc.

The ALL CAPS CSS_… Strings I use often when I’m building FX controls so that I can have a single place to get to the style sheets. I do the same for Images that I might reuse or just anything really that I have to access more than once, I end up tossing into that C class just cause it makes it a little easier to code that way… but what I would like to know, is … am I doing this the right way? Or the “prescribed” way? Or is there some other method I should be considering?

I would like my coding style to be as … “universal” as I can get it, not only because I would like it to be viewed by others without causing their heads to spin, but also in the interest of writing efficient and succinct code all around.