Saturday, December 8, 2012

System.out.println


public class Sysout_class {
   
    public static void main(String[] args) {

    System.out.println("Hello");
    //As you can see from the Oracle Spec the following lines are written
    /*
    * %W% %E%
    *
    * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
    * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
    */

    //(A) In System Class it calls the PrintStream class
    /*       
    System is a final class defined in java.lang.*
       
    public final class System {
    }

    * 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.
    * <p>
    * For simple stand-alone Java applications, a typical way to write
    * a line of output data is:
    * <blockquote><pre>
    *     System.out.println(data)
    * </pre></blockquote>
    * <p>
    * See the <code>println</code> methods in class <code>PrintStream</code>.
    *
    * @see     java.io.PrintStream#println()
    * @see     java.io.PrintStream#println(boolean)
    * @see     java.io.PrintStream#println(char)
    * @see     java.io.PrintStream#println(char[])
    * @see     java.io.PrintStream#println(double)
    * @see     java.io.PrintStream#println(float)
    * @see     java.io.PrintStream#println(int)
    * @see     java.io.PrintStream#println(long)
    * @see     java.io.PrintStream#println(java.lang.Object)
    * @see     java.io.PrintStream#println(java.lang.String)
   
    public final static PrintStream out = nullPrintStream();
   
    private static PrintStream nullPrintStream() throws NullPointerException {
    if (currentTimeMillis() > 0) {
        return null;
    }
    throw new NullPointerException();
    }
   
               
    (B)It goes to the PrintStream class
    public void println(String x) {
    synchronized (this) {
        print(x);
        newLine();
    }
    }
   
    (B1)
    public void print(String s) {
    if (s == null) {
        s = "null";
    }
    write(s);
    }
   
    (B2)
    private void write(String s) {
    try {
        synchronized (this) {
        ensureOpen();
        textOut.write(s);
        textOut.flushBuffer();
        charOut.flushBuffer();
        if (autoFlush && (s.indexOf('\n') >= 0))
            out.flush();
        }
    }
    catch (InterruptedIOException x) {
        Thread.currentThread().interrupt();
    }
    catch (IOException x) {
        trouble = true;
    }
    }   
   
    public void write(String str) throws IOException {
    write(str, 0, str.length());
    }
   
    (B3)
    public void write(String str) throws IOException {
    write(str, 0, str.length());
    }
   
    (C)   
    private BufferedWriter textOut;
   
    BufferedWriter's Super class is Writer Class and in that class it calls the write method
    print(x) finally goes to private BufferedWriter textOut;
 
    public void write(String str) throws IOException {
    write(str, 0, str.length());
    }
   
    (D)
    Similarly for newLine() from PrintStream class (B) the same procedures as (B1), (B2), (B3) and (C) follows;
    */
    }
}

No comments:

Post a Comment