当前位置:网站首页>今天终于会写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
边栏推荐
- Makefile文件是什么?
- [leetcode daily question] 396 Rotation function
- W801 / w800 WiFi socket development (I) - UDP
- How to install mysql-5.7.9 in RPM mode under Linux system
- 什么是代理IP池,如何构建?
- English abbreviation of role personal attribute
- Introduction to esp32 Bluetooth controller API
- RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimensio
- Error in face detection and signature of Tencent cloud interface
- Shardingsphere read write separation
猜你喜欢

What are the common proxy IP problems?

Introduction to micro build low code zero Foundation (lesson 2)

42、使用mmrotate中k3det进行旋转目标检测,并进行mnn部署和ncnn部署

Uncover floating-point operations hidden by the ARM compiler

腾讯云接口进行人脸检测 和签名出错问题

Technology cloud report: cloud computing has entered the "second half". Where is the way out for domestic cloud?

J-Link RTT使用

How to write the resume of Software Test Engineer so that HR can see it?

About how to import C4d animation into lumion

How to classify proxy IP?
随机推荐
搭建个人主页保姆级教程(二)
How to set computer IP?
中金财富是国企吗,开户安全吗
在使用代理IP前需要了解哪些分类?
教程】如何用GCC“零汇编”白嫖MDK
Problem solving: dpkg DEB: error: package name has characters that are't lowercase alphanums or '- +‘
How to install mysql-5.7.9 in RPM mode under Linux system
领导/老师让填写电子excel表格文档可手机上如何编辑word/excel文件填写excel/word电子文档?
Ziguang micro financial report is outstanding. What does the triple digit growth of net profit in 2021 depend on
什么是bgp服务器,有哪些优势?
单片机和4G模块通信总结(EC20)
2022 low voltage electrician examination questions and answers
Use Xdebug breakpoint debugging in postman
Do447 manage user and team access
如何设置电脑ip?
Esp32 message queue using FreeRTOS
Makefile文件是什麼?
RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimensio
Encrypted compressed backup bat script
What business scenarios will the BGP server be used in?