2008-03-13
解读java.lang.System
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()是不会被显示的。只仅仅调试的时候才有控制台。但该控制台只能输出。
发表评论
- 浏览: 64407 次
- 性别:

- 来自: 广州

- 详细资料
搜索本博客
最新评论
-
JavaEye之路
引用我也很喜欢JavaEye,比CSDN好 CSDN太杂了规模大了能不大而全吗? ...
-- by Sam1860 -
JavaEye之路
我在这,随便说点啥,博客,论坛,都说我应该是一个新手的帖子。不过我还是呆在这。反 ...
-- by saharabear -
我是穷忙族
-- by lbyzx123 -
JavaEye之路
javaeye目前的问题: 1,缺乏一个好的盈利模式,商业化运作 2,技术定位 ...
-- by kimmking -
JavaEye之路
我也很喜欢JavaEye,比CSDN好 CSDN太杂了
-- by lovefly_zero






评论排行榜