Last updated 2004-06-28 by Roedy
Green ©1996-2004 Canadian Mind Products
Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
You are here : home : Java Glossary : P words : preferences.
On Linux, they are stored in the file system in the /etc/.java directory for system preferences and the ~/.java directory for user preferences.
In theory, a JVM could hide them in an SQL database or any other scheme it concocted.
Here is how you use them:
import java.util.prefs. Preferences; ... // get object for storing preferences for MyClass private Preferences userPrefs = Preferences.userNodeForPackage ( MyClass.class ); ... // store preferences, key=value userPrefs.putInt( "width" , width ); userPrefs.putInt( "height", height ); ... // fetch preferences, key,default int width = userPrefs.getInt( "width", 100 ); int height = userPrefs.getInt( "height", 200 );
systemNodeForPackage lets you specify preferences for the whole machine for each package. userNodeForPackage lets you specify preferences for a particular user for that package. If the package is used in more than one context, e.g. the same class used in two different programs or the same class is used to manage two separate sets of files, it is up to you to create another level of name to keep track of the context. Note though you specify a class name, the preferences are on a per package, not a per class basis.
User preferences show up at My_Computer\HKEY_CURRENT_USER\Software\JavaSoft\Prefs\com\mindprod\replicator and My_Computer\HKEY_USERS\usernamexxx\Software\JavaSoft\Prefs\com\mindprod\replicator where the package name is com.mindprod.replicator.
System preferences show up at My_Computer\HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs\com\mindprod\replicator.
The registry will be more legible with regedit if you stick to lower case keys and values.
home |
Canadian Mind Products | |||
| mindprod.com IP:[24.87.56.253] | ||||
| Your IP:[80.134.30.163] | ||||
| You are visitor number 1337. | ||||
| Please send errors, omissions and suggestions | ||||
| to improve this page to Roedy Green. | ||||
| You can get a fresh copy of this page from: | or possibly from your local J: drive mirror: | |||
| http://mindprod.com/jgloss/preferences.html | J:\mindprod\jgloss\preferences.html | |||