I've just started learning Java after getting the hang of C++, and I'm wondering if there is a way that I can have global constants the same way in C you can have a Header file with a list of constants that you can just include in any class files that need to use them. Right now, in my Java project, I am achieving this effect by using a Java interface with the constants defined as final variables.
public interface Constants {
public int constant1 = 36;
public String projectName = "Project Name";
public float ratio = 4.716f;
// ... more parameters
}
To access them in my class files that they are used in, I just use the implements keyword in the class files.
public class Class1 implements Constants {
// Members
// ...
// Methods
// ...
}
It's not that this isn't working, I'm just wondering if this is the best way to get this effect. I'm not formally trained in Java, I'm just teaching myself from some books I've gotten and online forums. I've looked around and I haven't found much discussion on this specific topic, more just about declaring constants within classes, so I'm just trying to figure out from some more experienced Java programmers with formal training if there is a more standard/conventional way to do this. Any advice would be helpful, thank you!