Is this String concatenation creating extra String? Using the eclipse formatting on a class with some @NamedQueries created concatenations.

While I have been doing this for years without paying attention I just realised that may be it
is  not a good usage.

So basically Which one of these Strings inside the queryis better ? Is the second one creating too many Strings? Should I be bothered at all?

My answer would be yes second one is creating extra Strings but I am not sure I should be concerned.

First Query

 @NamedQuery(
      name = SomeConstant,
      query="SELECT person FROM Person person Where person.name = :name ")


Second Query

 @NamedQuery(
      name = SomeConstant,
      query="SELECT person FROM Person person"+" "+
               "Where person.name = :name ")
Enter the mad world of optimization!

The Java compiler and HotSpot just-in-time compiler are programmed with a great many rules for optimizing performance of Java code.

In general, it is NOT worth your time to fret about the performance impact of these kinds of details as they are often taken care of. Rather, just try to write clean readable code that solves the problem. If performance is an issue, profile the code and then optimize the bottlenecks.

Now, to address this specific issue, I am virtually certain that constant expressions are resolved by the Java compiler at compile time. I would be very surprised if the byte code for your two queries wasn't identical.