Java Programing laungage

java.util Projects

java.util Project 1

Saving and Retrieving The Preferences

In this page of tutorials we shall be learn about the way to retrieving the user preference node using the same class saves and retrieves a preference in the node. for better understanding we take an example.

Previous Home Next

Preference values are the constant and stored in the key/value pairs. In the pairs the value must a string and these values are stored in a node. This preference node is associated with java package and if a class named saveretrievpreference then class is need to save some preferences, it must save them in the preference node associated with the package r4r.

Example


package r4r;
import java.util.*;
import java.util.prefs.Preferences;
public class saveretrievpreference {
public static void main(String[] args) {
saveretrievpreference preffinal = new saveretrievpreference();
}



public saveretrievpreference() {
String str = "R4RTechSoft Solution";
Preferences pre = Preferences.userNodeForPackage(this.getClass());
pre.put("Preference Value", str);
String str1 = pre.get("Preference Value", "");
System.out.println("Got Preference Value '" + str1 + "' from preference");
 }
}

Previous Home Next