Home Java Example Java Util java preferences,Change the value of Preferences by user



java preferences,Change the value of Preferences by user
Posted on: April 17, 2011 at 12:00 AM
This page discusses - java preferences,Change the value of Preferences by user

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

Related Tags for java preferences,Change the value of Preferences by user:


More Tutorials from this section

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

Post your Comment


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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.