advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement


Title: Java Internationalization
ISBN: 0596000197
US Price: $ 39.95

© 2001 O'Reilly & Associates, Inc.

Reviews : Java Books :
Java Internationalization : Isolating Locale-Specific Data With Resource Bundles

A property resource bundle is a collection of text elements in a properties file format
stored in a .properties file. The PropertyResourceBundle class provides all code
necessary for you to access these resources in a locale-dependent manner.

Example 4-10 illustrates basic property file formatting. The Properties class in the
java. util package handles reading and writing properties files. Both the keys to
lookup a value and the values returned are Java Strings. Example 4- 10 shows a
simple properties file.

Example 4-10. A Properties File

# Sample properties file for demonstrating PropertyResourceBundle class
#
# Text that will appear in the title bar of our application
ApplicationTitle= Demonstrating the use of PropertyResourceBundle
#
# Text that will be displayed on OK buttons
OKButtonLabel= OK
#
# Text for display on a button to cancel current operation
CancelButtonLabel= Cancel
#
#

A property in a properties file is specified in the following format: Key= Value

In most properties files, you see that the separator between key and value is the equals sign (=) character. Java also allows use of the colon (:) character as a separator between key and value, as in: Key: Value

We won't go into all the details about how Java deals with properties files, but here are a few general comments on how properties files are structured: lines starting with an exclamation (!) or a pound (#) character are ignored when the properties file is read. These characters indicate that the line is a comment line. Keys are case sensitive. Finally, you can specify values in a properties file that span multiple lines by using a backslash ( \ ) to indicate line continuation. Example 4-11 illustrates this point.

Example 4-11. Properties File Where Values Span More Than One Line (AnimalResources. properties)

# Sample properties file with keys whose values span more than one line
#
Animals= Cat, Dog, Giraffe, \
Shark, Dolphin, Bird, \
Bear, Moose

If you retrieved the "Animals" key, you'd get back the value Cat, Dog, Giraffe, Shark, Dolphin, Bird, Bear, Moose. All the leading whitespace on any continuation line is discarded. You could then, for example, break up the value returned to you by using the java. util. StringTokenizer class.

Example 4-12 uses the properties file from Example 4-11 to print a list of animal names.

Example 4-12. Printing a List of Animals Stored in a Properties Resource File

import java. util. Locale;
import java. util. ResourceBundle;
import java. util. MissingResourceException;

public class Animals {

  public static void main( String [] argv) {

    ResourceBundle animalResources;

    try {
      animalResources = ResourceBundle. getBundle(
        "AnimalResources", Locale. getDefault());
      System. out. println( animalResources. getString(" Animals"));
    } catch (MissingResourceException mre) {
      mre. printStackTrace();
    }
  }
}

Here is the output produced after running Example 4-12:

C:\> java Animals

Cat, Dog, Giraffe, Shark, Dolphin, Bird, Bear, Moose

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Microsoft Visual Studio 2010 Showcase
 Avaya Developer Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 39
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Windows 7: From Beta to Final Code in One Year
Google Shows Off Chrome OS, Releases Source
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?
Fedora 12 Takes Aim at Linux Networking
Top Supercomputer Nearly Doubles in Speed
Fedora 12 Linux Tackles Virtualization
Apple Gives iPhone Developers App Status Tracker
Novell Sets OpenSUSE 11.2 Free

Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Exploring HTML 5's Audio/Video Multimedia Support
Overriding Virtual Functions? Use C++0x Attributes to Avoid Bugs.
Understanding the Cloud Computing Security Vulnerabilities
Cisco and IBM Target a Greener World
Upgrade to Visual Studio 2010 with the Ultimate Offer

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs