In java I have seen different approaches to declare the constants. Using interface and class
Assume that some of my class need to use a constant which is hardcoded and can be accessed Constants.MY_CONSTANT_1
Can any one share the memory usage difference of Constant declaration using class and an interface.
Using java interface
public interface Constants{
int MY_CONSTANT_1=100;
int MY_CONSTANT_2=200;
}
Using Java Class
public class Constants{
public static final int MY_CONSTANT_1=100;
public static final int MY_CONSTANT_2=200;
}
Kindly summarize :
- What is the best approach
- Is there any other better approaches