• Post Reply Bookmark Topic Watch Topic
  • New Topic

when to use the preferences api?

 
Leon Webster
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JDK 1.4 added a preferences API, and according to the Design FAQ "It is intended to replace most common uses of Properties, rectifying many of its deficiencies, while retaining its light weight."
I was coding a small database application, and decided that I should put the url for the database driver and four or five other bits of information into a properties file so that a) they weren't hard coded and b) they could be easily moved from my development enviroment into a production environment and modified for that environment. since I knew that there was this new API, read about it in Gregory Travis' _JDK 1.4 Tutorial_ and most of the online Sun documentation. But I am unconvinced of its usefulness.
First, I can't find an easy way to hand-code preferences files. Admittedly, as the design FAQ says, properties files are "brittle" and easily broken by careless editing, but it seems a bit much write a program to store a few strings. Secondly, once I have a preferences file established, I have to have another program to export them from one enviroment and into another enviroment. In many ways the whole point of properties files is to make this sort of portability easy.
But I also know the preferences api was written by Joshua Bloch who wrote _Effective Java_ a book that i liked a lot. So I am not willing to write the preferences api off with out thinking about it for just a bit.
My question for the forum is: "has anyone migrated system configuration information from properties files to the preferences api, and what have the results been?" Were you pleased with the experience? How do you migrate from one platform to another?
Thanks for any input.
Leon Webster
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not played with Preferences, but just glancing at the API, it looks like there is an export/import capability to an XML format. Seems to me that should be pretty easy to edit.
Bill
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!