resource bundle in Java

A resource bundle contains the local specific objects to be used by a program. It is like a map with keys and values. The resource bundle can be in a property file or in a Java class.
Below is a property file Zoo_en.properties. Notice that the filenames are the name of our resource bundle followed by an under-score followed by the target locale.
```
hello=Hello
open=The zoo is open.
```
Below code show how to use it,
```
import java.util.Locale;
import java.util.ResourceBundle;

public class Main {
    public static void main(String[] args) {
        ResourceBundle rb = ResourceBundle
                .getBundle("Zoo", new Locale("en", "US"));
        rb.getString("hello"); // Hello
    }
}
```
To implement a resource bundle in Java, you create a class with the same name that you would use for a property file. Only the extension is different. Since we have a Java object, the file must be a .java file rather than a .properties file.
There are two main advantages of using a Java class instead of a property file for a resource bundle:
* You can use a value type that is not a String .
* You can create the values of the properties at runtime.

<b>Picking a resource bundle for French in France with default locale US English</b>
* Always look for the property file after the matching Java class.
* Drop one thing at a time if there are no matches. First drop the country and then the language.
* Look at the default locale and the default resource bundle last.

Step | Looks for File | Reason
----- | ----- | -----
1 | Zoo_fr_FR.java | The requested locale
2 | Zoo_fr_FR.properties | The requested locale
3 | Zoo_fr.java | The language we requested with no country
4 | Zoo_fr.properties | The language we requested with no country
5 | Zoo_en_US.java | The default locale
6 | Zoo_en_US.properties | The default locale
7 | Zoo_en.java | The default language with no country
8 | Zoo_en.properties | The default language with no country
9 | Zoo.java | No locale at all—thedefault bundle
10 | Zoo.properties | No locale at all—the default bundle
11 | If still not found, throw MissingResourceException | 

<b>Factory methods to get a NumberFormat</b>
Description | Using Default Locale and a Specified Locale
----- | -----
A general purpose formatter | NumberFormat.getInstance()<br>NumberFormat.getInstance(locale)
Same as getInstance | NumberFormat.getNumberInstance()<br>NumberFormat.getNumberInstance(locale)
For formatting monetary amounts | NumberFormat.getCurrencyInstance()<br>NumberFormat.getCurrencyInstance(locale)
For formatting percentages | NumberFormat.getPercentInstance()<br>NumberFormat.getPercentInstance(locale)
Rounds decimal values before displaying (not on the exam) | NumberFormat.getIntegerInstance()<br>NumberFormat.getIntegerInstance(locale)

The parse method parses only the beginning of a string. After it reaches a character that cannot be parsed, the parsing stops and the value is returned.

<b>ofLocalized methods</b>
DateTimeFormatter f = DateTimeFormatter.???(FormatStyle.SHORT);| Calling f.format(localDate) | Calling f.format (localDateTime) or (zonedDateTime) | Calling f.format (localTime)
----- | ----- |----- | -----
ofLocalizedDate | Legal—shows whole object | Legal—shows just date part | Throws runtime exception
OfLocalizedDateTime | Throws runtime exception | Legal—shows whole object | Throws runtime exception
ofLocalizedTime | Throws runtime exception | Legal—shows just time part | Legal—shows whole object

```
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;

class Main {
    public static void main(String[] args) {
        LocalDate date = LocalDate.of(2020, Month.JANUARY, 20);
        LocalTime time = LocalTime.of(11, 12, 34);
        LocalDateTime dateTime = LocalDateTime.of(date, time);

        DateTimeFormatter shortDateTime =
                DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT);
        System.out.println(shortDateTime.format(dateTime)); // 1/20/20
        System.out.println(shortDateTime.format(date)); // 1/20/20
        System.out.println(shortDateTime.format(time)); // UnsupportedTemporalTypeException
    }
}
```