JDK 1.4 Preferences API

Upon reading the new Preferences API in JDK 1.4, came across that :

To get the user preferences, we would use:

Preferences prefs = Preferences.userRoot().node("/com/foo/myApp");

To get the system preferences, we would use:

Preferences prefs = Preferences.systemRoot().node("/com/foo/myApp");

What is package name doing here ???
In the JDK1.3 era of Properties files, we used to pass the name of the properties file...etc...
How do we tell the Preferences Object here, where the hell is my properties file ???

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

From : http://java.sun.com/j2se/1.4/docs/guide/lang/preferences.html

   1. How does this Preferences API relate to Properties API?

      It is intended to replace most common uses of Properties, rectifying many of its deficiencies, while retaining its light weight. When using Properties, the programmer must explicitly specify a pathname for each properties file, but there is no standard location or naming convention. Properties files are "brittle", as they are hand-editable but easily corrupted by careless editing. Support for non-string data types in properties is non-existent. Properties cannot easily be used with a persistence mechanism other than the file system. In sum, the Properties facility does not scale.

JituAuthor Commented:
girionis >
I read the article, i still have following questions :

1. Which 'user' is being referred to here ?
Preferences prefs = Preferences.userRoot().node("/com/foo/myApp");

Is this OS user ? In case of Windows NT, the logged in user in the Windows machine ??

That would occur as a strange thing to me, because, my application would usually have registered user (example in a web application), and i would be interested in their user preferences. I am confused about this.

It seems OS user is being referred here.

2. I did not understand the need of hierarchy here especially its association with packages.
Here is what i mean :

My properties file in JDK 1.3 era would look like :

oracleUserId = myUser
oraclePassswd = myPasswd
oracleTimeOut = 3
SkinToUse = StarAndStripes
PostLoginImage = welcome1.jpg

How would i use this in my code to pick up this information or even set this information, from any class in my packages. The package names as u can see are irrelevant to me in this case, the whole application uses the same properties file.

Now, what is the use of converting this into a hierarchy. Can anyone explain with a example ?

1) Under Linux/Unix it is the user that is currently logged in. Sorry, not sure about Windows.

2) If your whole application uses the same property files and there is no need for hierarchy then I'd say there is no need to use the Preferences class. Anyhow, if you still want to use these values you will have to use the put() method (for String) or the put<type> for the rest (take a look at the Preferences API for more info: http://java.sun.com/j2se/1.4/docs/api/java/util/prefs/Preferences.html). You can also look at some source code examples here: http://javaalmanac.com/egs/java.util.prefs/pkg.html

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.