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.

Results 1 to 5 of 5

Thread: detailed description

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default detailed description

    How does System.out.println() works?


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: detailed description

    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

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: detailed description

    Quote Originally Posted by helloworld922 View Post
    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:

    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.
    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.

    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:

    JTable table = new JTable();
    String tableValue = table.getModel().getValueAt(0,0).toString();
    String parsedValue = tableValue.subString(0, 5).toUpperCase().replaceAll("1", "ONE");

    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!

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: detailed description

    Quote Originally Posted by KevinWorkman View Post
    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.

    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:

    JTable table = new JTable();
    String tableValue = table.getModel().getValueAt(0,0).toString();
    String parsedValue = tableValue.subString(0, 5).toUpperCase().replaceAll("1", "ONE");

    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()
    I just popped the question into google and linked one of the results. My bad for not thoroughly examining the contents

    Thanks for the corrections/clarifications.
    Last edited by helloworld922; April 8th, 2011 at 12:05 AM.

  5. #5
    Junior Member
    Join Date
    Jul 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: detailed description

    Quote Originally Posted by helloworld922 View Post


    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!