Consider the following code
public static void method(String[] srgs){
try{
}catch(){
System.out.println("Hello World" + "one");}
catch(..){
System.out.println("Hello World" + "two");}
catch(..){
System.out.println(getString());}
}
When are these Strings created? I assume the Strings will get created when an Exception occurs at run time. The string gets created at run time and is displayed. A peer of mine tells me that since these are constant Strings they will get created as soon as the Class loads. Is that correct?
When are the Strings garbage collected? Are they garbage collected at all ? Assuming the same method may get called many times in the programs life time does it not make sense to just cache them?