首页 文章

什么是Java中的System.out.println()中的System,out,println [复制]

提问于
浏览
37

可能重复:Java中System.out.println的含义是什么?

我正在寻找Java中 SystemoutprintlnSystem.out.println() 中的答案 . 我搜索并找到了这样的不同答案:

  • System是java.lang包中的内置类 . 这个类有一个final修饰符,这意味着它不能被其他类继承 . 它包含预定义的方法和字段,提供标准输入,输出等功能 .

  • out是System类中的静态final字段(即变量),其类型为PrintStream(内置类,包含打印不同数据值的方法) . 必须使用类名来访问静态字段和方法,因此(System.out) .

  • out此处表示PrintStream类类型的引用变量 .

  • println()是PrintStream类中用于打印数据值的公共方法 . 因此,要访问PrintStream类中的方法,我们使用out.println()(因为非静态方法和字段只能使用refrence varialble访问)

在另一个页面中,我发现另一个对比定义为

System.out.print是java中使用的标准输出函数 . 其中System指定包名称,out指定类名称,print是该类中的函数 .

我很困惑这些 . 有人可以告诉我它们是什么吗?

3 回答

  • 11

    您发布的第一个答案(系统是一个内置类......)非常适合 .

    您可以添加 System 类包含大部分本机且在启动期间由JVM设置的部分,例如将 System.out printstream连接到与"standard out"(控制台)关联的本机输出流 .

  • 108

    Systemjava.lang 包中的最终类 .

    outSystem 类中声明的 PrintStream 类型的类变量 .

    printlnPrintStream 类的方法 .

  • 8

    每当您感到困惑时,我建议您咨询Javadoc作为您澄清的第一个地方 .

    从javadoc关于 System ,这是文档所说的内容:

    public final class System
    extends Object
    
    The System class contains several useful class fields and methods. It cannot be instantiated.
    Among the facilities provided by the System class are standard input, standard output, and error output streams; access to externally defined properties and environment variables; a means of loading files and libraries; and a utility method for quickly copying a portion of an array.
    
    Since:
    JDK1.0
    

    关于 System.out

    public static final PrintStream 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)
    

相关问题