当前位置:网站首页>今天终于会写System.out.println()了
今天终于会写System.out.println()了
2022-04-23 01:55:00 【Sivan_Xin】
最近在整理IO流的笔记时,发现了这样一个问题······
理解 System.out.println()
在Java.lang包下有一个System类,其中定义了一个类(静态)成员变量:
public final static PrintStream out = null;
由此可见,out只不过是PrintStream的一个对象。由于out在System类中是静态修饰的,所以可以直接通过类名来调用System.out
。(System.in也是一样的道理,这里就不详细说了。)
现在,我们拿到了PrintStream类的一个对象System.out
,通过对象调用方法(println)就更好理解了,所以就得到了这样的语句System.out.println
。
//一般不会有人这样写,只是便于理解。
PrintStream Myout = System.out;
Myout.println("Sivan");
空指针的out
这里out作为对象但是声明为null。但是为什么没有抛出NullPointerException?
因为在System类中有一个静态初始化块:
/* register the natives via the static initializer. * * VM will invoke the initializeSystemClass method to complete * the initialization for this class separated from clinit. * Note that to use properties set by the VM, see the constraints * described in the initializeSystemClass method. */
private static native void registerNatives();
static {
registerNatives();
}
JVM在加载类时,就是通过registerNatives()
这个静态方法给out赋了初始值,至于具体的操作,可以参考这篇文章:https://zhidao.baidu.com/question/38660871.html。
由此可见,Java中万事万物皆对象。
最重要的来啦~~~
码字不易,求个关注
点个收藏不迷路哦~
版权声明
本文为[Sivan_Xin]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_62633072/article/details/124347816
边栏推荐
- Nanny level tutorial on building personal home page (II)
- Dimension C China helping farmers in rural areas warms people's hearts the third stop is jiabaoguo farm
- Performance introduction of the first new version of cdr2022
- npm——配置淘宝镜像
- PID精讲
- After disk D is distributed to Disk C, what should I do if the database recovery hangs? Please answer
- EBS:PO_EMPLOYEE_HIERARCHIES_ALL
- 有哪些常见的代理ip问题?
- 搭建个人主页保姆级教程(二)
- The leader / teacher asks to fill in the EXCEL form document. How to edit the word / Excel file on the mobile phone and fill in the Excel / word electronic document?
猜你喜欢
如何对代理IP进行分类?
最长公共子序列(记录路径版)
动态代理ip的测试步骤有哪些?
Solve the problem when installing MySQL
The sixth season of 2022, the perfect children's model IPA national race leads the yuanuniverse track
有哪些常见的代理ip问题?
Leetcode 112 Total path (2022.04.22)
About how to import C4d animation into lumion
揭秘被Arm编译器所隐藏的浮点运算
Encrypted compressed backup bat script
随机推荐
Esp32 message queue using FreeRTOS
NPM -- configure Taobao image
Do447 manage user and team access
C语言实现Base64编码/解码
使用代理IP是需要注意什么?
领导/老师让填写电子excel表格文档可手机上如何编辑word/excel文件填写excel/word电子文档?
浅析一下隧道代理IP的优缺点。
电子采购如何成为供应链中的增值功能?
What is an API interface?
Cc2541 emulator CC debugger tutorial
W801 / w800 WiFi socket development (II) - UDP Bluetooth control WiFi connection
What is a dial-up server and what is its use?
Introduction to micro build low code zero Foundation (lesson 2)
Use Xdebug breakpoint debugging in postman
What is a makefile file?
拨号vps会遇到什么问题?
keil mdk中文乱码,两种解决方法,字体不再难看
What code needs unit testing?
W801 / w800 / w806 unique ID / CPUID / flashid
Sqlserver data transfer to MySQL