wood burning stoves 2.0*
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
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: 61657
    
  67

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: 18996
    
  40

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: 61657
    
  67

Probably just being lazy. I do not approve.

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

Joined: Oct 14, 2005
Posts: 18907
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why do this - PrintStream ps = System.out; ?