Search code examples
spring-bootstatic-variablesmemory-efficientapplication.properties

application properties vs static variables


While working on a Spring Boot project I got this doubt that what is better to use to Save Constant Values, application properties file or a Java Interface?

To get value from application.properties we have to declare variables in every file where for Java Interface, we will have only one declared variable referred everywhere.

Any other advantage one over other. Can anyone figure out in terms of memory efficiency?


Solution

  • The advantage of using application properties is you can change the value without changing code. If you think something is likely to change, or if it is different for different environments, then it would make sense to put it in the properties. You can define multiple profiles and have a properties file for each profile if needed.

    If you are sure something isn’t going to change then define a constant. In that case you’re assigning a name to a value to improve the readability of the code.

    This kind of thing seems unlikely to be significant enough for it to matter for performance. Performance improvement is about identifying and addressing the biggest bottleneck. This is going to be a long way down the list.