Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
 
 
Search All Tutorials

 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Saving and Retrieving The Preferences

                         

Preference values are the constant  key/value pairs. In the pairs of key and value the key must be a string and the preference values are stored in a node. The preference node associated with java package and if a class named roseindia.class needs to save some preferences, it must save them in the preference node associated with the package roseindia.

In this section you will learn about the way to retrieves the user preference node using the same class and saves and retrieves a preference in the node. Here an example is also provided for learning about the topic in detailed form.

Here is the Complete Code of the Example :

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.
	}
}

 

After thoroughly knowing the code you should save the file by "PrefFinal.java" file name and when after compiling the code you run your program you will get the output given below . 

Here is the Output of the Example :


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

C:\Documents and Settings\Microsoft\Desktop\roseindia>java PrefFinal
Got PrefsValue 'roseindia' from prefs

In the above example we stored the value "roseindia" and retrieve it via user's instruction.

Download This Example

                         

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Hot Web Programming Job

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.