Reputation: 4006
What is the difference between maintaining application properties in
plain java objects
example:
public class AppProp {
public static final String RESOURCE_NAME="RESOURCE VALUE";
}
and maintaining in seperate property file.
I am asking this question based on memory and performance of accessing the resource.
Upvotes: 1
Views: 296
Reputation: 1074266
Using final statics like that will certainly be faster, and possibly more memory-efficient, than using a properties file, especially when using a JIT-enabled bytecode interpreter (e.g., most of them). Using a properties file is preferred, however, when the resource values in question need to be localizable or configurable without code changes.
Upvotes: 0
Reputation: 5980
It all comes down to flexibility. There are 3 reasons I can see for using properties files over statics.
1) They can be modified without changing and rebuilding the code.
2) The values can be modified/overridden inside the application while it is running.
3) They allow for multiple instances of the same code to run along side each other in the same JVM with different configurations. This can happen with some third party libraries.
The java.util.Property class contains support for loading from a stream, so you can just load once and re-use that instance. Unless the only thing your application does is property lookups or you have an enormous number of attributes I would not worry too much about overhead here.
Upvotes: 3