首页 arrow 开发技术 arrow 程序设计 arrow 解读java.lang.System
解读java.lang.System
Author Author: 一滴蔚蓝色 | Date Date: 2008-09-08 | View Count View: 499 | Section & Category 开发技术 - 程序设计 | Digg Digg: 0

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);
}

  1.  可以看到跟C里面的putchar是一样的,实际上是调用C的putchar。
  2. System是静态类。提供系统的便利方法。
  3. System没有输入流。注意手机并没有控制台,像window下的dos或者linux的bash shell。没有该方面的功能。
  4. 当程序运行在手机上,调用System.out.println()是不会被显示的。只仅仅调试的时候才有控制台。但该控制台只能输出。


更多阅读:

 

尚无评论发表

我要发表评论

登录菜单

最新文章

订阅本站

RSS 0.91 RSS 1.0 RSS 2.0 ATOM 0.3 OPML