java 学习之System这个类源码的解读

只要是学习Java后端的对于Java基础知识想必都非常的清楚,非常的有自信,我也是,仗着自己有两年Java开发经验,认为自己的基础很是扎实,结果,当我刷了面试题后发现并不是这样。发现有些东西自己只是简单的会用而已: 比如Java给我们内嵌好的Java.lang下的好多类,我们只是会使用它们常用的,具体它们有哪些功能,有哪些方法,我们一无所知,这就是悲哀啊。仅仅会用的东西,还摸棱两可的使用。好了进入正题:

System.out.println();这个输出语句,包含哪些知识呐,我们来看一下,首先,System这个是Java.lang包下的一个类

那你可能该联想了那么out是不是System类下的一个对象呐,再继续推,那println()是不是System类的方法呐。

如果你得出这样的答案,我还能说什么呐,只能说你该好好看看源码了,正确答案是:out对象不是System类的对象,println()确实是System类的方法。 通过看源码发现out对象是

/** * The "standard" output stream. This stream is already * open and ready to accept output data. Typically this stream * corresponds to display output or another output destination * specified by the host environment or user. *

* For simple stand-alone Java applications, a typical way to write * a line of output data is: *

*     System.out.println(data)
* 

*

* See the println methods in class PrintStream. * * @see java.io.PrintStream#println() * @see java.io.PrintStream#println(boolean) * @see java.io.PrintStream#println(char) * @see java.io.PrintStream#println(char[]) * @see java.io.PrintStream#println(double) * @see java.io.PrintStream#println(float) * @see java.io.PrintStream#println(int) * @see java.io.PrintStream#println(long) * @see java.io.PrintStream#println(java.lang.Object) * @see java.io.PrintStream#println(java.lang.String) */

public final static PrintStream out = null;
是PrintStream的对象,是不是感觉发现了新大陆,接下来我们把System类中常用的方法,以及作用介绍一下。

System.in这个是标准的输入,in这个对象对应的类是InputStream
System.out这个是标准的输出
System.err这个是标准的输出错误
System.exit(-1)这个是退出
public static native long  currentTimeMillis();这个是返回当前的时间在毫秒
public static native long nanoTime();这个是返回当前的时间在纳秒
public static native void arraycopy(Object src,  int  srcPos,
                                    Object dest, int destPos,
                                    int length);
                                    这个是copy的方法,当需要copy大量代码时需要用它
复制代码

好了这些就是最常用的了,想了解更多,请去看System的源码。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值