The answer has already been given here:
Java: System.out.println and System.err.println do not work
This is because your last sentence uses System.out, and the other code uses System.err. The error stream merges before the output stream or vice versa.
As a result, the print data order will not be guaranteed to be issued in the same order as it is.
You can always connect the console to the error stream to a file or the output stream to a file for later verification. Or change your code to print everything on System.out. Many programmers do not use ERR and the utility is controversial if you do not capture the err separately from the console.
Just use it!
Again and again...
Saint hill
source share