Home Java Example Java Util java preferences,Change the value of Preferences by user
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

java preferences,Change the value of Preferences by user

Advertisement
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

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 17, 2011

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

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com