Free tutorials for Java, Eclipse and Web programming



Follow me on twitter

Java Preferences API - Tutorial

Lars Vogel

Version 1.1

29.05.2011

Revision History
Revision 0.116.10.2007Lars Vogel
Created
Revision 0.2 - 1.129.09.2008 - 29.05.2011Lars Vogel
bug fixes and enhancements

Abstract

This article gives a introduction into the Java Preference API to save key/value pairs for an application.


Table of Contents

1. Java Preferences API
2. Using the API
3. Thank you
4. Questions and Discussion
5. Links and Literature
5.1. vogella Resources

1. Java Preferences API

The Preferences API provides a systematic way to handle program preference configurations, e.g. to save user settings, remember the last value of a field etc.

Preferences are key / values pairs where the key is an arbitrary name for the preference. The value can be a boolean, string, int of another primitive type. Preferences are received and saved by get and put methods while the get methods also supply a default value in case the preferences is not yet set.

This Java Preferences API is not indented to save application data.

The Java Preference API removes the burden from the individual programmer to write code to save configuration values on the different platforms his program may be running.

The actual storage of the data is dependent on the platform.