How does Java decide when a new String should be created? 
I assume it depends on the specific JVM implementation/ compiler, but I thought the results of this test were interesting enough to ask the question:
class A { public String test = "test";}
class B { public String test = "test";}
...
public static void main (String[] args)
{
    String test = "test";
    System.out.println(test == "test");                // true
    System.out.println(test == new String("test"));    // false
    System.out.println(new A().test == new B().test);  // true
}
 
    