java preferences,Change the value of Preferences by user

This page discusses - java preferences,Change the value of Preferences by user

Ads

Tutorials   
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
Ads

Change the value of Preferences by user

     

In this example you will learn how can a user change the preferences value by the user value. Here we are going to make it easier to understand by the complete example on this topic. In the given example we explain a simple way for using the get() and put() method in preferences. In preferences the get() is the most useful method with the help of which you can stored data in the class and can change by put() method. In this example the value which is stored by get method will display only one time but then after the value will show the user value when you run it second time. If we consider the example the first time when you run the example it shows the value it stored "deepak" , and "rinku" but when you run the same program it will display the user information "rose" and in the second line it will show "india".

Here is the Complete Code of The Example :

import java.util.prefs.Preferences;

public class base 
  {
  public static void main(String[] args) 
  {
  Preferences prefs = Preferences.userNodeForPackage(base.
class);
  String text = prefs.get("name one""deepak");
  String display = prefs.get("name two""rinku");
  System.out.println(text);
  System.out.println(display);
  prefs.put("name one""rose");
  prefs.put("name two""india");
  }
  } 

Just save the example as "base.java"

Here is the Output of The Example :

C:\Documents and Settings\Microsoft\Desktop>javac base.java

C:\Documents and Settings\Microsoft\Desktop>java base
deepak
rinku

C:\Documents and Settings\Microsoft\Desktop>javac base.java

C:\Documents and Settings\Microsoft\Desktop>java base
rose
india

In the output it clearly shows that on the first compilation and running time the value is as in the get method but when it compiled second time the value change as "rose" and "india"

Download This Example

Advertisements

Share on Google+Share on Google+

java preferences,Change the value of Preferences by user

Posted on: April 17, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: java preferences,Change the value of Preferences by user  

Post your Comment


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

Ads

 

Ads