This is because Java evaluates operands from left to right. Quoting section 15.7:
The Java programming language guarantees that the operands of operators appear to be evaluated in a specific evaluation order, namely, from left to right.
String s=10+30+" Sachin "+40+40;
// ^^^^^ + the operands are of type int so int addition is performed
String s=40+" Sachin "+40+40;
// ^^^^^^^^^^^^^ + the operands are of type int and String so String concatenation is performed
String s="40 Sachin "+40+40;
// ^^^^^^^^^^^^^^^ + the operands are of type int and String so String concatenation is performed
String s="40 Sachin 40"+40;
// ^^^^^^^^^^^^^^^^^ + the operands are of type int and String so String concatenation is performed
String s="40 Sachin 4040";
The behaviour of + when one of the operands is a String is specified in section 15.18.1 about the "String Concatenation Operator +":
If only one operand expression is of type String, then string conversion (§5.1.11) is performed on the other operand to produce a string at run time.