aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Sytstem.out.format Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Sytstem.out.format" Watch "Sytstem.out.format" New topic
Author

Sytstem.out.format

Mrinal Singhania
Greenhorn

Joined: Sep 30, 2012
Posts: 7
Hi,



The first line prints "true", while the second throws an exception. I don't understand why? AFAIK, booleans are not equivalent to ints/doubles, in that true != 1 and false != 0 in java.

Can someone please explain.

Thanks.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16686
    
  19

Take a look at the javadoc for the java.util.Formatter class, particularly the chart about the behavior for each type.

'b', 'B'
general
If the argument arg is null, then the result is "false". If arg is a boolean or Boolean, then the result is the string returned by String.valueOf(arg). Otherwise, the result is "true".


Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Mrinal Singhania
Greenhorn

Joined: Sep 30, 2012
Posts: 7
Henry Wong wrote:Take a look at the javadoc for the java.util.Formatter class, particularly the chart about the behavior for each type.

'b', 'B'
general
If the argument arg is null, then the result is "false". If arg is a boolean or Boolean, then the result is the string returned by String.valueOf(arg). Otherwise, the result is "true".


Henry


Hi Henry,

Thanks for the reply. And this solves my problem

Regards.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Sytstem.out.format
 
Similar Threads
Printf (not enough resources)
simple print statement
Logical Operators
printf() method clarification required
printf string formatting