This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Why do this - PrintStream ps = System.out; ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why do this - PrintStream ps = System.out; ?" Watch "Why do this - PrintStream ps = System.out; ?" New topic
Author

Why do this - PrintStream ps = System.out; ?

justin smythhe
Ranch Hand

Joined: Jul 06, 2012
Posts: 107
what is the purpose ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 63053
    
  69

To assign System.out to ps.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
justin smythhe
Ranch Hand

Joined: Jul 06, 2012
Posts: 107
Bear Bibeault wrote:To assign System.out to ps.

Lol ! Agree ! But why not do System.out.print(); instead ?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19927
    
  43

justin smythhe wrote:
Bear Bibeault wrote:To assign System.out to ps.

Lol ! Agree ! But why not do System.out.print(); instead ?


One possibility -- a configuration option. The default option may be to print to standard out.... but the code wants the ability to route the output elsewhere, without routing the actual standard out. With a level of indirection, you can change where the standard output goes with a one line change of this config.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 63053
    
  69

Probably just being lazy. I do not approve.

Or what Henry suggested, which is better but ...
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19693
    
  10

justin smythhe wrote:
Bear Bibeault wrote:To assign System.out to ps.

Lol ! Agree ! But why not do System.out.print(); instead ?


Because then you can just do ps.print(); instead. Less typing, right?

But really, System.out.println isn't a major feature of most real-life programs, so as Bear suggests, that's unnecessary laziness.
 
 
subject: Why do this - PrintStream ps = System.out; ?
 
It's not a secret anymore!