L
lsrinu
who will create the object out for the System class, where we find the
method println();
method println();
lsrinu said:who will create the object out for the System class, where we find the
method println();
I'm not sure if this is actually answering your question, but still....
There's is no object which has the println() method.
That method (like all the methods of java.lang.System) is
static, which means that the method is part of
the class, but is not attatched to any specific
instance of that class.
So you call it by using the name of the class rather
then via some object:
java.lang.System.println("whatever");
There sure is...
Bjorn said:Immediately at startup, "out" is set to null, but as soon as the JVM has
initialized the thread, it calls some private native methods to instantiate
the object.
Dale said:There is a static method initializeSystemClass which is the one that
actually sets them to wrappers around FileInputStream or
FileOutputStream. It does use native calls to actually do the setting.
Probably because it needs to coordinate with native code that can also
print messages.
Thomas said:It uses native methods because those statics are final (they weren't in
1.00). The Java Memory Model has to make an exception for
System.in/out/err. The should have been methods. 1.1 should probably
have made them proxies, so setIn/setOut/setErr could have worked in a
sensible fashion.
Dale said:It might have been nice if they did something like .NET did with
properties where you can access them using field-like syntax but have it
actually use methods.
Thomas said:As I understand it, .NET makes that approach useless. Switching from a
field to a property will break binary compatibility. So you still need
to make sure all your fields are private.
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.