Preferences Overview

In this section you will learn about preferences and all the methods that modify preference data are allowed to operate a certain work. It allow to store the user and system configuration data.



How to read properties file in Java? Generate random numbers in Java Cloneable Interface in Java What is the flaw with the Stack class? List In Java Java Stack Example HashSet In Java Enumeration in java How to generate random number in java Iterator in java Queue in java Transient Java Keyword clone method in Java Java Queue example Logger in Java Java current date - How to get current date in Java Collection : LinkedList Example Collection : ArrayList Example Random alpha numeric string of fixed size Java List Iterator Example The Hashtable Class The BitSet class Java Vector Java Enumeration Data Structures in Java Java Transient Variable Java Date Format Example Java Properties File Example Map.Entry Java Interface Java Property File java preferences,Change the value of Preferences by user Retrieving a Preference Node Java hasNext Write Keys and Values to the Properties file in Java Get All Keys and Values of the Properties files in Java Properties file in Java Properties file in Java Determining If a Preference Node Contains a Specific Value Change the value of Preferences by user Clone method example in Java Implementing a Simple Event Notifier Determining When a Preference Node Is Added or Removed Listening for Changes to Preference Values in a Preference Node Importing Preferences Finding a Preference in a Preference Tree Retrieving the Parent and Child Nodes of a Preference Node Determining If a Preference Node Exists Removing a Preference Node Creating a Preference Node Getting the Maximum Size of a Preference Key and Value

Preferences Overview


In this section you will learn about preferences and all the methods that modify preference data are allowed to operate a certain work. It allow to store the user and system configuration data. In the preference class it can call many threads on a single Java Virtual Machine (JVM)  while the result will be same as execution and all of the methods that modify preference data are permitted to operate asynchronously.
There are two separate trees of preference nodes  

1- System preferences ( Every one can use like installation configuration data for an application.)

2- User Preferences ( User define like font, color, or preferred window location and size for a particular application.)  

At each level in the tree we have a map of key or value pairs. Any node in a preference tree may contain other nodes and may contain preference data. The types of data that can be stored as preferences are as under.


Package :

Here we are going to make it easier to understand by the complete example in this topic here we illustrate all the methods used in this package and also explain that what are the uses of them. All the method which is used for Preferences are described below gets a Preference object associated with the package of the current application it all about to the method preferences of the java.util package. It is really very important for the application can take the preferences and configured data for  many users and environments. Here is the package named  java.util.prefs which gives the path for applications to store and retrieve the preference and configured data. Preferences stored as a tree structure based upon class structure.

There are two of the method with the help of which the preferences returns a Preferences Object. Let us consider that our PreferenceTestFrame class is defined in the roseindia.preferences package. The call of the Preferences.userNodeForPackage(this) returns a Preferences object that is associated with the roseindia.preferences/ node in the user preferences tree. If that node does not exist it will be created.

Every value of the preference data stored using the Preferences API is stored in a particular node in one of the two preference trees and has a String key value with it which must be unique within that particular node of the tree. There are seven kind of "get" methods and also there are seven kind of  "put" methods in the Preferences class, every method for each of the valid preference types.

get() method --

1-  int getInt(String key, int default)

2-  float getFloat(String key, float default)

3-  long getLong(String key, long default)

4-  double getDouble(String key, double default)

5-  boolean getBoolean(String key, boolean default)

6-  byte[] getByteArray(String key, byte[] default)

7-  String get(String key, String default)

Each of the "get" methods accepts a default value. This value will be returned if the specified key does not exist at that particular node. They keys() method returns an array of String objects that includes all of the keys stored at that particular node.

put() method :

1-void putInt(String key, int value)

2-void putFloat(String key, float value)

3-void putLong(String key, long value)

4-void putDouble(String key, double value)

5-void putBoolean(String key, boolean value)

6-void putByteArray(String key, byte[] value)

7-void put(String key, String value)

The implementation of any preference data stores in the Windows Registry and the address of that stored data under HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Prefs and user preferences are stored under HKEY_CURRENT_USER\Software\JavaSoft\Prefs. These are the two path where the preferences data are stored.



Share on Google+Share on Google+

Preferences Overview

Posted on: February 27, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Preferences Overview  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image