Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ResourceBundles & Properties  RSS feed

 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems clear that these two classes are very much intertwined.
If I have a simple properties file it seems quickest and easiest to use the ResourceBundle to look up the different values. Only if I need to update it in some way, do I need the Properties class.
Is this the standard procedure for this kind of thing?
Thanks.
Paul
 
Dave Landers
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ResourceBundle is much more than (different than) just properties.
First, a ResourceBundle is localizable (internationalizable) so you can override it based on the runtime locale.
Also, a ResourceBundle might be implemented by a file or it could be implemented by a Class. The classes are also localizable.
So ResourceBundle is really good for holding stuff that needs that localization (like message text, button labels, etc).
But a properties file is exactly that - it is a file (not a class) and it is not localized. So properties are good place for configuration variables and things that determine how the system runs (like number of threads in a queue or settings for factories, etc).
One nice thing that ResourceBundle has is the ability to get a bundle conveniently - namely the getBundle() factory method. I think a lot of people use ResourceBundle when they really needed Properties because "hey, it's easier, it must be right".
But you can get almost the same effect with:

The only thing missing is the caching that getBundle does.
I use a subclass for Properties that implements the above loading semantics in a factory method. I also added convenience methods for doing string conversions to integer, boolean, etc (as in getPropertyAsInt, etc).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!