Java - weird static String behavior - new String("xxx") vs "xxx"

Viewed 1396
public class Test {

    private static final String str1 = new String("en");
    private static Test instance = initInstance();

    private static final String str2 = new String("en");
    private static final String str3 = "en";

    private Test() {
    }

    public static void main(String[] args) {
    }

    private static Test initInstance() {
        instance = new Test();
        System.out.println(str1 + ',' + str2 + ',' + str3);
        return instance;
    }
}

Theoretically with statics everywhere it should result in "en,en,en".

Result: "en,null,en"

Expected: "en,null,null" (since i discovered statics order actually matters)

Could somebody explain this? What is so different about "en" and new String("en")?

3 Answers
Related