A Preferences object represents a mapping between preference names, which are case-sensitive strings, and corresponding preference values. get( ) allows you to query the string value of a named preference, and put( ) allows you to set a string value for a named preference. Although all preference values are stored as strings, various convenience methods whose names begin with “get” and “put” exist to convert preference values of type boolean byte[ ], double, float, int, and long to and from strings.

The remove( ) method allows you to delete a named preference altogether, and clear( ) deletes all preference values stored in a Preferences object. The keys( ) method returns an array of strings that specify the names of all preferences in the Preferences object.

Preference values are stored in some implementation-dependent back-end which may be a file, a LDAP directory server, the Windows Registry, or any other persistant “backing store”. Note that all the get( ) methods of this class require a default value to be specified. They return this default if no value has been stored for the named preference, or if the backing store is unavailable for any reason. The Preferences class is completely independent of the underlying implementation, except that it enforces an 80-character limit for preference names and Preference node names (see below), and a 8192-character limit on preference value strings.

Preferences does not have a public construtor. To obtain a Preferences ...

Get Java in a Nutshell, 5th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.