public class HelloWorld { /** * * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Hello World"); } }
$ javac HelloWorld.java $ java HelloWorld Hello World
public final class System { /** * Default input stream. */ public static final InputStream in; /** * Default output stream. */ public static final PrintStream out; /** * Default error output stream. */ public static final PrintStream err; private static final String lineSeparator; private static Properties systemProperties; static { err = new PrintStream(new FileOutputStream(FileDescriptor.err)); out = new PrintStream(new FileOutputStream(FileDescriptor.out)); in = new BufferedInputStream(new FileInputStream(FileDescriptor.in)); lineSeparator = System.getProperty("line.separator"); }
/** * Prints a string followed by a newline. The string is converted to an array of bytes using * the encoding chosen during the construction of this stream. The bytes are * then written to the target stream with {@code write(int)}. * * <p>If an I/O error occurs, this stream's error state is set to {@code true}. * * @param str * the string to print to the target stream. * @see #write(int) */ public synchronized void println(String str) { print(str); newline(); }
public synchronized void print(String str) { if (out == null) { setError(); return; } if (str == null) { print("null"); return; } try { if (encoding == null) { write(str.getBytes()); } else { write(str.getBytes(encoding)); } } catch (IOException e) { setError(); } }
public synchronized void write(int oneByte) { if (out == null) { setError(); return; } try { out.write(oneByte); int b = oneByte & 0xFF; // 0x0A is ASCII newline, 0x15 is EBCDIC newline. boolean isNewline = b == 0x0A || b == 0x15; if (autoFlush && isNewline) { flush(); } } catch (IOException e) { setError(); } }
public class FileOutputStream extends OutputStream { private FileDescriptor fd; private final boolean shouldClose; /** The unique file channel. Lazily initialized because it's rarely needed. */ private FileChannel channel; /** File access mode */ private final int mode; private final CloseGuard guard = CloseGuard.get();
public final class FileDescriptor { /** * Corresponds to {@code stdin}. */ public static final FileDescriptor in = new FileDescriptor(); /** * Corresponds to {@code stdout}. */ public static final FileDescriptor out = new FileDescriptor(); /** * Corresponds to {@code stderr}. */ public static final FileDescriptor err = new FileDescriptor(); /** * The Unix file descriptor backing this FileDescriptor. * A value of -1 indicates that this FileDescriptor is invalid. */ private int descriptor = -1; static { in.descriptor = STDIN_FILENO; out.descriptor = STDOUT_FILENO; err.descriptor = STDERR_FILENO; }
@Override public void write(byte[] buffer, int byteOffset, int byteCount) throws IOException { IoBridge.write(fd, buffer, byteOffset, byteCount); } @Override public void write(int oneByte) throws IOException { write(new
深入理解 Java HelloWorld,布布扣,bubuko.com
原文:http://blog.csdn.net/jingxia2008/article/details/34448313