Is a static class kept along with it’s static variables in the memory after using it once, or is it instantiated along with every variable every time I use it?
To make it more real lets create an example.
Let’s say I want to make a language dictionary for my system not using singletons.
My static language class with 2 static variables:
package server;
import java.util.Locale;
import java.util.ResourceBundle;
public abstract class Language {
private static Locale language = new Locale("en", "GB");
public static ResourceBundle dictionary = ResourceBundle.getBundle("dictionary_"+Language.language, Language.language);
public static void changeLanguage(Locale language){
Language.language = language;
Language.dictionary = ResourceBundle.getBundle("dictionary_"+Language.language, Language.language);
}
}
When I use it in the system to get a tekst value like so:
System.out.println(Language.dictionary.getString("system.name"));
Will the whole class along with dictionary static variable stay in memory until I use it again, or will it be created again, and again eating my memory every time I do so?