代码之家  ›  专栏  ›  技术社区  ›  Dinup Kandel

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

  •  39
  • Dinup Kandel  · 技术社区  · 12 年前

    可能重复:
    What's the meaning of System.out.println in Java?

    我在寻找什么的答案 System , out println System.out.println() 在Java中。我搜索了一下,找到了一个不同的答案,如下所示:

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

    • out是System类中的一个静态最终字段(即变量),其类型为PrintStream(一个内置类,包含打印不同数据值的方法)。 静态字段和方法必须使用类名so(System.out)进行访问。

    • out表示PrintStream类类型的引用变量。

    • println()是PrintStream类中用于打印数据值的公共方法。 因此,为了访问PrintStream类中的方法,我们使用out.println()(因为非静态方法和字段只能通过使用refence variable来访问)

    在另一页中,我发现另一个对比鲜明的定义是

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

    我被这些弄糊涂了。有人能确切地告诉我它们是什么吗?

    3 回复  |  直到 7 年前
        1
  •  115
  •   Sotirios Delimanolis    8 年前

    System 是来自 java.lang 包裹

    out 是类型为的类变量 PrintStream 在中声明 系统

    println 是一种方法 打印流

        2
  •  11
  •   Sujay    12 年前

    每当你感到困惑时,我建议你咨询 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)
    
        3
  •  8
  •   pap    12 年前

    你发布的第一个答案(System是一个内置类…)非常准确。

    您可以添加 System 类包含很大一部分是本机的,由JVM在启动期间设置,例如连接 System.out printstream到与“标准输出”(控制台)关联的本地输出流。