public final class System { private System() {} public final static PrintStream out = getConsoleOutput(); private static PrintStream getConsoleOutput() { return new PrintStream(new SystemOutputStream()); } public final static PrintStream err = out; public static native long currentTimeMillis(); public static native void arraycopy(Object src, int src_position, Object dst, int dst_position, int length); public static native int identityHashCode(Object x); public static String getProperty(String key) { if (key == null) { throw new NullPointerException("key can't be null"); } if (key.equals("")
) { throw new IllegalArgumentException("key can't be empty"); } return getProperty0(key); } private native static String getProperty0(String key); public static void exit(int status) { Runtime.getRuntime().exit(status); } public static void gc() { Runtime.getRuntime().gc(); }}
-------------------------------------------
System.out應用SystemOutputStream。我們看看它是怎樣的:
public class SystemOutputStream extends OutputStream { synchronized public void write(int c) throws IOException { putchar((char) c); } private static native void putchar(char c);}
可以看到跟C裡面的putchar是一樣的,實際上是調用C的putchar。System是靜態類。供給系統的方便方法。System沒有輸進流。留心手機並沒有把持台,像window下的DOS或者Linux的bash shell。沒有該方面的功效。當程序運行在手機上,調用System.out.println()是不會被顯示的。只僅僅調試的時候才有把持台。但該把持台只能輸出。