Re: Is System.in an object?
On Apr 27, 10:16 am, "shuch...@gmail.com" <shuch...@gmail.com> wrote:
On Apr 27, 9:04 am, tenxian <hi.steven...@gmail.com> wrote:
I think System is an object and in is one of System's fields. Can
someone give me a clarification?
System.out.println(System.in.getClass().getName())
public final static InputStream in = nullInputStream();
/**
* The following two methods exist because in, out, and err must
be
* initialized to null. The compiler, however, cannot be
permitted to
* inline access to them, since they are later set to more
sensible values
* by initializeSystemClass().
*/
private static InputStream nullInputStream() throws
NullPointerException {
if (currentTimeMillis() > 0)
return null;
throw new NullPointerException();
}
private static PrintStream nullPrintStream() throws
NullPointerException {
if (currentTimeMillis() > 0)
return null;
throw new NullPointerException();
}
/**
* Initialize the system class. Called after thread
initialization.
*/
private static void initializeSystemClass() {
props = new Properties();
initProperties(props);
sun.misc.Version.init();
FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
setIn0(new BufferedInputStream(fdIn));
setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true));
setErr0(new PrintStream(new BufferedOutputStream(fdErr, 128), true));
// Load the zip library now in order to keep java.util.zip.ZipFile
// from trying to use itself to load this library later.
loadLibrary("zip");
// Currently File.deleteOnExit is built on JVM_Exit, which is
a
// separate mechanism from shutdown hooks. Unfortunately in
order to
// work properly JVM_Exit implicitly requires that Java signal
// handlers be set up for HUP, TERM, and INT (where
available). If
// File.deleteOnExit were implemented in terms of shutdown
hooks this
// call to Terminator.setup() could be removed.
Terminator.setup();
// Set the maximum amount of direct memory. This value is controlled
// by the vm option -XX:MaxDirectMemorySize=<size>. This method acts
// as an initializer only if it is called before
sun.misc.VM.booted().
sun.misc.VM.maxDirectMemory();
// Subsystems that are invoked during initialization can invoke
// sun.misc.VM.isBooted() in order to avoid doing things that should
// wait until the application class loader has been set up.
sun.misc.VM.booted();
// The main thread is not added to its thread group in the
same
// way as other threads; we must do it ourselves here.
Thread current = Thread.currentThread();
current.getThreadGroup().add(current);
// Allow privileged classes outside of java.lang access to
ConstantPool
sun.misc.SharedSecrets.setJavaLangAccess(new
sun.misc.JavaLangAccess(){
public sun.reflect.ConstantPool getConstantPool(Class
klass) {
return klass.getConstantPool();
}
});
}