aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes does this make sense? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "does this make sense?" Watch "does this make sense?" New topic
Author

does this make sense?

Mellihoney Michael
Ranch Hand

Joined: Nov 27, 2002
Posts: 124
Boolean b=new Boolean("abcd");
[ February 15, 2003: Message edited by: Mellihoney Michael ]

a beginner in java
Piotr Kaluski
Greenhorn

Joined: Jan 31, 2003
Posts: 8
Yes, it does.
There is a constructor for Boolean which takes a literal. If the literal is "True" (case does not matter), the object wraps true. If it is something else (like "abcd") the object will wrap "false".


Piotr Kaluski<br />SCJP 1.4
Sarma Lolla
Ranch Hand

Joined: Oct 21, 2002
Posts: 203
Hi the following are from JAVA API on Boolean class for valueOf methods.
My question is when we send a string as parameter to Boolean.ValueOf method is the return value is one of Boolean.TRUE / Boolean.FALSE? If so like in ValueOF(boolean) why doesn't API specify the same?


public static Boolean valueOf(boolean b)Returns a Boolean instance representing the specified boolean value. If the specified boolean value is true, this method returns Boolean.TRUE; if it is false, this method returns Boolean.FALSE. If a new Boolean instance is not required, this method should generally be used in preference to the constructor Boolean(boolean), as this method is likely to to yield significantly better space and time performance.
Parameters


public static Boolean valueOf(String s)Returns a Boolean with a value represented by the specified String. The Boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string "true".

[ February 13, 2003: Message edited by: Sarma Lolla ]
[ February 13, 2003: Message edited by: Sarma Lolla ]
[ February 13, 2003: Message edited by: Sarma Lolla ]
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
It is often a nice and interesting expedition to go see the JDK source code. In this case, we have to look at the class java.lang.Boolean. Below is the constructor Boolean(String) constructor as well as one of the private toBoolean() method invoked within the body of the constructor.

Form the code we case see, as Piotr mentioned, that if the value of the given String object is "true" (whatever the case) then the Boolean object will wrap a true else a false.
Remember: the answer is out there
[ February 13, 2003: Message edited by: Valentin Crettaz ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Piotr Kaluski
Greenhorn

Joined: Jan 31, 2003
Posts: 8
Were can I find the source code for JDK?
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
In the src.zip file bundled with the J2SE release.
Otherwise you can go there:
http://wwws.sun.com/software/java2/download.html
[ February 14, 2003: Message edited by: Valentin Crettaz ]
 
wood burning stoves
 
subject: does this make sense?