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

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.