Home » Java programming language

Java ResourceBundle clearCache() Method with Example

ResourceBundle Class clearCache() method: Here, we are going to learn about the clearCache() method of ResourceBundle Class with its syntax and example.
Submitted by Preeti Jain, on March 24, 2020

ResourceBundle Class clearCache() method

Syntax:

    public static final void clearCache();
    public static final void clearCache(ClassLoader cl);
  • clearCache() method is available in java.util package.
  • clearCache() method is used to clear all ResourceBundle from the cache that has been moved from the given caller class ClassLoader.
  • clearCache(ClassLoader cl) method is used to clear all ResourceBundle from the cache that has been moved from the given parameter class loader.
  • These methods may throw an exception at the time of clearing the cache.
    NullPointerException: This exception may throw when the given parameter is null exists.
  • These are static methods and it is accessible with the class name and if we try to access these methods with the class object then also we will not get an error.

Parameter(s):

  • In the first case, clearCache(),
    • It does not accept any parameter.
  • In the second case, clearCache(ClassLoader cl),
    • ClassLoader cl – represents the class loader.

Return value:

In both the cases, the return type of the method is void – it returns nothing.

Example:

// Java program to demonstrate the example 
// of clearCache() method of ResourceBundle

import java.util.*;

public class ClearCacheOfResourceBundle {
 public static void main(String[] args) {
  // Instantiates ResourceBundle with
  // some locale
  ResourceBundle rb = ResourceBundle.getBundle("IncludeHelp...", Locale.FRANCE);

  // Display message for the given
  // key element "IncludeHelp..."
  System.out.println("" + rb.getString("IncludeHelp..."));

  // By using clearCache() method is to
  // clear cache
  ResourceBundle.clearCache();
  System.out.println("Cache Operation Completed.");

  // By using clearCache() method is to
  // clear cache by the given class loader

  ClassLoader cl = ClassLoader.getSystemClassLoader();
  ResourceBundle.clearCache(cl);
  System.out.println("Cache Operation Completed.");
 }
}

Output

IncludeHelp… = Website



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.