Literal Strings versus Literal Integers
Look at the following code snippet:
System.out.println( 3 + 1 );
System.out.println( "3" + 1 );
System.out.println( 3 + 1 + "3");
What's the output of each line? Run the code below to see.
Let's work through the code above.
On the first line, the + works as an addition operator because both operands (the things on either side of the operator) are integers. 3 plus 1 is 4.
On the second line, the + works as a concatenation operator because one of the operands is not a number. The String 3 concatenated with the integer 1 is the new String "31".
The third line makes use of both the addition operator and concatenation operator. 3 plus 1 is read first and evaluated to 4 using the addition operator. The 4 is then concatenated to the front of the String "3" resulting in the String "43" being displayed.
You will need to be comfortable with both addition and concatenation, and, the more you use them, the more comfortable you will become.