Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Multiple Value initialization and retrieval by put and get method 
 

In this example you are going to find out the flow of using put and get method of the preferences. After reading, coding, and running you are able to use the get and put method.

 

Multiple Value initialization and retrieval by put and get method

                         

In this example you are going to find out the flow of using put and get method of the preferences. After reading, coding, and running you are able to use the get and put method. Here we are using some extra package method like Arrays, Iterator here you can see that how firstly in program we putting the value of the preferences like int type ,Boolean type, and simple key value after that we are just using the get method we access all the stored value of the preferences. As we recently completed all of the put and get type, some of them are given here for knowing them more clearly.

Here is the code of the Program :

package roseindia;
import java.util.Arrays;
import java.util.Iterator;
import java.util.prefs.Preferences;

public class Basic {
  public static void main(String[] args) throws Exception {
    Basic basic = new Basic();
  }

  public Basic() throws Exception{
    Preferences prefs = Preferences.userNodeForPackage(this.getClass());
    prefs.put("city1""delhi");
    prefs.putInt("intValue"2);
    prefs.putBoolean("booleanValue"true);
    int usageCount = prefs.getInt("intValue", 0);
    usageCount++;
    prefs.putInt("UsageCount", usageCount);
    Iterator it = Arrays.asList(prefs.keys()).iterator();
    while (it.hasNext()) {
      String key = it.next().toString();
      System.out.println(key + ": " + prefs.get(key, null));
    }
  }
}

After thoroughly knowing the code you should save the file by "Basic.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 Program :

C:\roseindia>javac Basic.java
C:\roseindia>cd..
C:\>java roseindia.Basic
city1: delhi
intValue: 2
booleanValue: true
UsageCount: 3
C:\>_

In the above Program the City1 and Delhi is putting as the default value and the all of the rest value is putting as the integer , Boolean value and after using the put function we are also use the get function via which we are just take from the contains preferences value for the output.

Download this example.

                         

» View all related tutorials
Related Tags: c string reference io method type boolean key rmi ole this ai node oo create if boo example to contains

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

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.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

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

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

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

Copyright © 2008. All rights reserved.