position of output of System.err.println(); is varying at the output even if position of it in code is similar. kindly please see the 4 cases with same position of System.err.println(); in it but its position in output is varying. please see the output at last of the program in comments.please Explain the Execution order.try the below code to see the astonishing output yourself.
public class System_Ex6 {
public static void main(String[] args)throws Exception {
System.out.println("-----------------case 1-------------------");
System.out.println("Java");
System.err.println("ErrorStatement<======Please observe the position of it "); //output comes in red ink color
System.out.println(System.getProperty("java.version"));
System.out.println(System.getProperty("os.name"));
//System.out.println(System.getProperty("os.version"));
System.out.println(System.getProperty("java.Vendor"));
//System.out.println(System.getProperty("os.version"));
System.gc();
System.out.println("-----------------case 2-------------------");
System.out.println("Java");
System.err.println("ErrorStatement<======Please observe the position of it "); //output comes in red ink color
System.out.println(System.getProperty("java.version"));
System.out.println(System.getProperty("os.name"));
//System.out.println(System.getProperty("os.version"));
System.out.println(System.getProperty("java.Vendor"));
//System.out.println(System.getProperty("os.version"));
System.gc();
System.out.println("-----------------case 3-------------------");
System.out.println("Java");
System.err.println("ErrorStatement<======Please observe the position of it "); //output comes in red ink color
//System.out.println(System.getProperty("java.version"));
System.out.println(System.getProperty("os.name"));
System.out.println(System.getProperty("os.version"));
System.out.println(System.getProperty("java.Vendor"));
//System.out.println(System.getProperty("os.version"));
System.gc();
System.out.println("-----------------case 4-------------------");
System.out.println("Java");
System.err.println("ErrorStatement<======Please observe the position of it "); //output comes in red ink color
System.out.println(System.getProperty("java.version"));
System.out.println(System.getProperty("os.name"));
//System.out.println(System.getProperty("os.version"));
System.out.println(System.getProperty("java.Vendor"));
System.out.println(System.getProperty("os.version"));
System.gc();
}//main()
}//class
/*
output:
=======
-----------------case 1-------------------
Java
1.8.0_74
Windows 8
null
ErrorStatement<======Please observe the position of it
-----------------case 2-------------------
Java
1.8.0_74
ErrorStatement<======Please observe the position of it
Windows 8
null
-----------------case 3-------------------
Java
ErrorStatement<======Please observe the position of it
Windows 8
6.2
null
-----------------case 4-------------------
Java
1.8.0_74
Windows 8
null
6.2
ErrorStatement<======Please observe the position of it
*/