How does System.out.println() works?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
How does System.out.println() works?
Are you talking about the underlying implementation? Or just the semantics of the calling syntax? if it's the latter, see How Does System.out.println work in Java
Interesting link. I'm not sure I really agree with how they described it though. One thing really stuck out to me:
Sure, out is a static variable. But it has nothing to do with the dot operator, or being unable to call methods on whatever is returned from another method. The biggest sign that it's a variable and not a method is simply the lack of () after it.Now, how do we categorize 'out'? Since println() is clearly a method, and its called using 'out', then we know that 'out' can not possibly be a method because it doesn't make sense to have one method invoke another method with the dot operator in Java. This means 'out' must be a variable.
To say that it doesn't make sense to have one method invoke another is simply wrong. Actually, this happens all the time. Here are a few examples:
I'm pretty skeptical about that programming interview site in general. I would say your first step to figuring out how System.out.println() works is to trace through the API:
System
.out
.println()
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Last edited by helloworld922; April 8th, 2011 at 12:05 AM.
Hi guys, thanks for the correction of the mistake - I am the owner of the site, and I have updated the page to reflect the correct information.
Of course, my opinion is biased but I think Software interview questions is a great site - and have received much input agreeing with that claim. I do try my best to clean up any errors - and I really appreciate you pointing this one out. If you see anything else please let me know.
Thanks!