• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
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?
 
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
 
Marshal
Posts: 59438
187
  • 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.
 
Sheriff
Posts: 21378
92
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.
 
Power corrupts. Absolute power xxxxxxxxxxxxxxxx is kinda neat.
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!