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.

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.

Preferences Overview

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.

1-int
2
-float
3-long
4-double
5-boolean
6-byte[]
7-String

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.