Strictly speaking, the Java compilers are a bit smarter in that the compiler does the concatenation on the string at compile for adjacent constant strings. In other words, the plus signs (concat operators) in the expression you give are not done at runtime. Both versions will store a single string in the constant pool, that will be loaded into the heap when assigned to a variable (or field). Result is that the GC will be called in both instances.

Been awhile since I've looked at the decompiled code, but just glancing at the results, I don't see any significant difference:


class TestMe {
private final String RETRIEVE_SQL = "select column1, column2 "
+ "from table "
+ "where AnyCommonWhereCondition ";

private static final String STATIC_SQL = "select column1, column2 "
+ "from table "
+ "where AnyCommonWhereCondition ";

public static void main(String argv[]) {
TestMe me = new TestMe();
}

TestMe() {
String s;

s = RETRIEVE_SQL;
s = STATIC_SQL;
}
}


.source TestMe.java
.class TestMe
.super java/lang/Object

.field private final RETRIEVE_SQL Ljava/lang/String;
= "select column1, column2 from table where AnyCommonWhereCondition "
.field private static final STATIC_SQL Ljava/lang/String;
= "select column1, column2 from table where AnyCommonWhereCondition "

.method public static main([Ljava/lang/String;)V
.limit stack 2
.limit locals 2
.line 11
new TestMe
dup
invokespecial TestMe/<init>()V
astore_1
.line 12
return
.end method

.method <init>()V
.limit stack 2
.limit locals 2
.line 14
aload_0
invokespecial java/lang/Object/<init>()V
.line 2
aload_0
ldc "select column1, column2 from table where AnyCommonWhereCondition "
putfield TestMe/RETRIEVE_SQL Ljava/lang/String;
.line 17
ldc "select column1, column2 from table where AnyCommonWhereCondition "
astore_1
.line 18
ldc "select column1, column2 from table where AnyCommonWhereCondition "
astore_1
.line 19
return
.end method