java.util.ListResourceBundle - Resource Bundles as Lists

This section provides a tutorial example on how to create resource bundles (localization key names with their localized text messages) as subclasses of the java.util.ListResourceBundle abstract class.

The ListResourceBundle class, java.util.ListResourceBundle, is an abstract subclass of the java.util.ResourceBundle class. It implements resource bundles as simple object list.

Now let's define some localization key names and localized text messages for some warning messages using subclasses of java.util.ListResourceBundle class:

1. Mapping WarningMessage key names to localized text messages for the default locale:

/* WarningMessage.java
 - Copyright (c) 2014, HerongYang.com, All Rights Reserved.
 */
import java.util.*;
public class WarningMessage extends ListResourceBundle {
   public Object[][] getContents() {
      return contents;
   }
   static final Object[][] contents = {
      {"LAST_MINUTE", "Bus is leaving within one minute."},
      {"HIGH_LOAD", "System load is very high."}
   };
}

Note that:

1. Mapping WarningMessage key names to localized text messages for the fr locale:

/* WarningMessage_fr.java
 - Copyright (c) 2014, HerongYang.com, All Rights Reserved.
 */
import java.util.*;
public class WarningMessage_fr extends ListResourceBundle {
   public Object[][] getContents() {
      return contents;
   }
   static final Object[][] contents = {
      {"LAST_MINUTE", "L'autobus part d'une minute."},
      {"HIGH_LOAD", "La charge de système est très haute."}
   };
}

3. Mapping WarningMessage key names to localized text messages for the fr and CA locale:

/* WarningMessage_fr_CA.java
 - Copyright (c) 2014, HerongYang.com, All Rights Reserved.
 */
import java.util.*;
public class WarningMessage_fr_CA extends ListResourceBundle {
   public Object[][] getContents() {
      return contents;
   }
   static final Object[][] contents = {
      {"HIGH_LOAD", "L'utilisation de système est très haute."}
   };
}

Last update: 2014.

Table of Contents

 About This JDK Tutorial Book

 Downloading and Installing JDK 1.8.0 on Windows

 Downloading and Installing JDK 1.7.0 on Windows

 Downloading and Installing JDK 1.6.2 on Windows

 Java Date-Time API

 Date, Time and Calendar Classes

 Date and Time Object and String Conversion

 Number Object and Numeric String Conversion

Locales, Localization Methods and Resource Bundles

 java.util.Locale - Localization and Internationalization

 Locale Sensitive Operations

 java.util.ResourceBundle - Resource Bundle Abstract Class

java.util.ListResourceBundle - Resource Bundles as Lists

 java.util.PropertyResourceBundle - Resource Bundles as Properties Files

 java.util.ResourceBundle.getBundle() - Retrieving Resource Bundles

 Calling and Importing Classes Defined in Unnamed Packages

 HashSet, Vector, HashMap and Collection Classes

 Character Set Encoding Classes and Methods

 Character Set Encoding Maps

 Encoding Conversion Programs for Encoded Text Files

 Socket Network Communication

 Datagram Network Communication

 DOM (Document Object Model) - API for XML Files

 SAX (Simple API for XML)

 DTD (Document Type Definition) - XML Validation

 XSD (XML Schema Definition) - XML Validation

 XSL (Extensible Stylesheet Language)

 Message Digest Algorithm Implementations in JDK

 Private key and Public Key Pair Generation

 PKCS#8/X.509 Private/Public Encoding Standards

 Digital Signature Algorithm and Sample Program

 "keytool" Commands and "keystore" Files

 KeyStore and Certificate Classes

 Secret Key Generation and Management

 Cipher - Secret Key Encryption and Decryption

 The SSL (Secure Socket Layer) Protocol

 SSL Socket Communication Testing Programs

 SSL Client Authentication

 HTTPS (Hypertext Transfer Protocol Secure)

 Outdated Tutorials

 References

 PDF Printing Version