What's the meaning of System.out.println in Java?

后端 未结 19 830
谎友^
谎友^ 2020-11-27 11:49

Is this static println function in out class from System namespace?

namespace System {
  class out {
    static println ...         


        
19条回答
  •  囚心锁ツ
    2020-11-27 12:40

    From the javadoc about System, here's what the doc says:

    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
    

    Regarding System.out

    public static final PrintStream out
    
    The "standard" output stream class Prinstream  belongs to java.io package. This stream is already open and ready to accept output data. 
    When the JVM is initialized, the method initializeSystemClass() is called that does exactly what it’s name says – it initializes the System class and sets the out variable. The initializeSystemClass() method actually calls another method to set the out variable – this method is called setOut().
    Typically this stream corresponds to display output or another output destination specified by the host environment or user.
    

    Regarding println();

    class PrintStream{
    public void println();
    }
    

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

    System.out.println(data);
    

提交回复
热议问题