System.err.println() 的输出位置;即使它在代码中的位置相似,输出也会发生变化。请查看 System.err.println() 位置相同的 4 个案例;在其中,但其在输出中的位置是不同的。请在评论中查看程序最后的输出。请解释执行顺序。尝试以下代码自己查看惊人的输出。
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
*/