I develop a webservice application in a tomcat container, I have a lot of properties for the webapp like constants, error messages and so on.
What is the better and faster way to?
I develop a webservice application in a tomcat container, I have a lot of properties for the webapp like constants, error messages and so on.
What is the better and faster way to?
public static final String SOME_CONSTANT = "contstantValue";
This makes the compiler inline the value, so you have nothing happening at runtime.
You can also store the values anywhere (.properties file) and load them in a static initializer block.
The answer, as always, is profile it.
In general, this is the sort of micro-optimization that almost certainly won't matter. Feel free to profile it and see, though.
Generally static constants; IO activity will always be slower.
However, hard-coding values means that the app will need to be recompiled if the value has to change. It's your call as a developer as to whether the values will ever need to be changed outside of a software release.
As Bozho says, in terms of raw speed, you're going to have trouble beating a public static final
. But speed isn't everything. If you need to worry about localization at all, for instance, a properties file would probably be better, although you might want to look at a ResourceBundle
instead.