views:

419

answers:

2

From past Year are so, we have developed an application, in which we have used the static String Constants to store the Constants. Like public static final String PAYMENT_CHEQUE = "cheque"; Where Ever I Require i.e. in the jsp pages as well the Action class I will be refering to the Above String Constant I am thinking after reviewing the Resource Bundle, properties Files, My Question is

  1. Is there any performance hit if I use the properties file compared to Static String Constant?
  2. Which is better Static string constant and Properties File Key Value pair?
  3. Is that good idea id we use the static String Constant(For Labeling) in the jsp?

Please suggest me

+2  A: 

In general, using hard-coded strings is a bad idea, because it means every change needs a new compilation-deployment cycle, whereas using a properties file means the application needs to be restarted and nothing else (although some would say that in itself is a high price to pay). Another advantage of using a properties file is the ability to switch languages by switching the application to another file - much more reasonable than having multiple sets of constant labels in code.

You can use the final static String fields the same way you do right now, only give them a value read fro ma properties file at the application's initialization stage, rather than going back to the file for every constant (which would be costly!). That way you don't have to make application-wide changes, and you still enjoy the advantages I mentioned above.

Yuval
+1  A: 

I would prefer resource bundles in this case:

  1. Your code is far more likely to have performance issues that resource bundles. Don't throw away a perfectly good technology without data to justify it.
  2. Resource bundles will allow you to internationalize your app easily; not so with static strings.
  3. It's a Java idiom that's easily implemented in JSPs if you're already using JSTL (and you should be).
duffymo