Is System.in an object?

T

tenxian

I think System is an object and in is one of System's fields. Can
someone give me a clarification?
 
S

shuchaoo

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();
}
});
}
 
C

Chase Preuninger

Yes, it is a final variable of type java.io.InputStream in the System
class
 
P

Patricia Shanahan

tenxian said:
I think System is an object and in is one of System's fields. Can
someone give me a clarification?

System.in is a static field in class System, of type InputStream. It
will almost always be a pointer to an object whose class extends
InputStream, but it can be null. Initially, it is a reference to an open
input stream attached to standard input.

Patricia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top