• Post Reply Bookmark Topic Watch Topic
  • New Topic

Advantages of using Console format over System.out.format  RSS feed

 
Linda Knecht
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the advantage of using the Console's API format and printf over the System.out.format and printf methods?
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as far as i know both methods do the same .\

--- edit

i just checked the API

System.out.format and String.format both create a Formatter object... so they do the same thing
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

You ought to try both when you start an application by double-clicking an executable .jar. You usually get no Console object; the reference will be null, and Console.printf will throw a NullPointerException. I don't know what happens to System.out under those circumstances.
 
Rob Spoor
Sheriff
Posts: 21131
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd say, only use Console if you need the readPassword methods. That's the only advantage it has over System.in, System.out and System.err.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!