Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

A question about K&B book

 
Ranch Hand
Posts: 74
Netbeans IDE Tomcat Server Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found this piece of code on page 501



Why did they call System.out.flush() here?

Doesn't the default output get automatically flushed by default?
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well technically no. Because it is a stream you need to flush it before it is guaranteed to be written.
Normally this will happen. Remember that you can change the default outputstream (not on the exam).
 
Mahmoud Hossam
Ranch Hand
Posts: 74
Netbeans IDE Tomcat Server Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Wouter Oet wrote:Well technically no. Because it is a stream you need to flush it before it is guaranteed to be written.
Normally this will happen. Remember that you can change the default outputstream (not on the exam).



I know you can change it by using setOut(), but since it wasn't changed, then this line is redundant, right?
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mahmoud Hossam wrote:I know you can change it by using setOut(), but since it wasn't changed, then this line is redundant, right?



According to my debugger, in stack of System.out.print(String s) (jdk 1.6)
following method of PrintStream is invoked:


So I don't see the difference between System.out.print() and System.out.println() methods in context of System.out.flush() invocation after them. It is redundant, right?


reply
    Bookmark Topic Watch Topic
  • New Topic