Java Programing laungage

java.util Projects

java.util Project 1

Change the value of Preferences by user

In this page of the tutorials we are going to learn how any user can change the preference value by the user input value.

Previous Home Next

Here we makes it easier to understand by this example. by the help of this example we explain a simple way for using the get() and put() method in preferences. In the preferences the get() method is the most useful method with help of this we can stored data into the class and we can change data by put() method. In this example the value which is stored by get() method will display only one time but then after the only user value will show when we run it second time.


package r4r;
import java.util.*;
import java.util.prefs.Preferences;
public class preferencevaluebyuser {
public static void main(String[] args) 
Preferences pre = Preferences.userNodeForPackage(preferencevaluebyuser.class); String str = pre.get("First Name", "Sam"); String str1 = pre.get("Second Name", "Kumar"); System.out.println(str); System.out.println(str1); pre.put("First Name", "R4R"); pre.put("Second Name", "TechSoft Solution"); } }
Previous Home Next