import java.util.prefs.*; public class PrefFinal{ public static void main(String[] args){ PrefFinal preffinal = new PrefFinal(); } public PrefFinal(){ String newvalue = "roseindia"; //Assign value "roseindia" to the String typed variable newvalue. Preferences prefs = Preferences.userNodeForPackage (this.getClass()); // This line declares the preferences for putting and getting the value from the current class. prefs.put ("PrefsValue", newvalue); //This line puts the value "rose" for the preferences key named newvalue. String prefs_value = prefs.get ("PrefsValue", ""); //This line gets your set preference value for the the defined preferences key. System.out.println("Got PrefsValue '" + prefs_value + "' from prefs"); //This prints the got preferences value whatever you have set. } }