File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes valueOf() method for Character Wrapper Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "valueOf() method for Character Wrapper Class" Watch "valueOf() method for Character Wrapper Class" New topic
Author

valueOf() method for Character Wrapper Class

Tanya Shetty
Ranch Hand

Joined: Jun 17, 2009
Posts: 40
Hey,

I am referring the SCJP 6 book by Kathy and Bert Bates...

Was referring table 3-3, Chapter 3, Page 243 for Wrapper Classes...

The valueOf() method in all numeric wrapper classes use a "string" or opt "string, radix" as an argument

For Boolean classes, valueOf() takes only "string" as a valid argument..as there is no radix for boolean

For Character classes however, valueOf() takes primitve type as an argument...

i.e. Character c = Character.valueOf('c');

Just did not find a mention of it in the text or the table 3-3.. came across it while on eclipse.. so thought of putting it down here..

If there is already an existing post of it.. sorry abt re-posting!

Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

I remember that there is a mistake. Please, have a closer look at Boolean class.


SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Tanya Shetty
Ranch Hand

Joined: Jun 17, 2009
Posts: 40
Yes, had a look at the Errata and found the Boolean class bug related to the parseBoolean("String") method which is missing in table 3-3

However, coming back to the earlier discussion...

In the Boolean class... there exist 2 static valueOf() method,,
valueOf(boolean type arg ) and valueOf(String arg)

In fact,, for all numeric wrapper classes there exists 3 types of valueOf() methods, ie Byte, Short, Integer,Long,Float,Double

valueOf(respective primitive type arg)
valueOf(String arg)
valueOf(String arg, int radix)

Only for Character, there is a single type of method valueOf(character type primitve arg)...

Also, this is not really a mistake in the book as it does indeed state...

The two (well, usually two) static valueOf() methods provided in most of the wrapper classes give you another approach to creating wrapper classes.


It's only that one could miss it if we dont dig into the Wrapper class method further.. and only rely on table 3-3
Nitish Bangera
Ranch Hand

Joined: Jul 15, 2009
Posts: 537

Go through the api for the wrappers. This thing will be clear.


[ SCJP 6.0 - 90% ] , JSP, Servlets and Learning EJB.
Try out the programs using a TextEditor. Textpad - Java 6 api
Tanya Shetty
Ranch Hand

Joined: Jun 17, 2009
Posts: 40
Yea.. got the above info after reading the API for a few wrapper classes only ... Its definitely helpful
 
wood burning stoves
 
subject: valueOf() method for Character Wrapper Class
 
Similar Threads
Wrapper Classes
Wrapper conversion methods..
valueOf() and parseXxx() for Character and Boolean wrapper classes - sounds like erratum in K&B
Doubt - 'valueOf' method
questions