wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Wrapper conversion methods.. 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 "Wrapper conversion methods.." Watch "Wrapper conversion methods.." New topic
Author

Wrapper conversion methods..

venkatesh badrinathan
Ranch Hand

Joined: Aug 03, 2008
Posts: 77
I guess the thing you are about to read will be bugging for those who reply.
please refer to kathy book pg:233, they have given a table mentioned WRAPPER CONVERSION METHODS and there are lot of stuff in it. i really could not interpret the table. can anyone explain me how to read that table.


SCJP1.5
Jamie MacDonald
Greenhorn

Joined: May 17, 2008
Posts: 20
The wrapper classes are listed across the top of the table. Each column shows whether that wrapper has the methods listed down the left side of the table. The parseXxx methods refer to the static methods which convert a String to a the primitive type associated with that wrapper. The Xxx is the primitive type that is returned (only capitalized to fit the Java naming conventions). If you are looking at the Float column, the method would be parseFloat(); If you are looking at the Integer column, the method would be parseInt(). If the wrapper has that method, there will be an "X" in the appropriate row for that column. So if you look at the row for the method doubleValue(), you will see that the Boolean wrapper class does not have that method, but the Byte wrapper class does.

[As an aside, the Java 6 version of K&B is out and has sufficient revisions to make the page numbers different. It would be helpful to note which edition of the book you are referencing.]
venkatesh badrinathan
Ranch Hand

Joined: Aug 03, 2008
Posts: 77
Thank you Mr.Jamie i have understood a portion of the table.. but how about parseXxx
(with radix), i do not know what is radix, also they have given as 'n' over there. do they imply that the method throws numberformatexception???(pg:233 in kathy 1.5 book ).also please let me know whether we have to memorise all the stuff given in that table??
Mario Razec
Greenhorn

Joined: Aug 01, 2008
Posts: 17
hi,
I understand that Radix refers to the base(octal, Hex...):

Example:
System.out.println(Integer.parseInt("100", 16));
----
parseXxx( "String number", Radix)

Checking: http://mindprod.com/jgloss/radix.html

Now 'n', I believe that NumberFormatException
parseXXX(String) throws NumberFormatException

See ya
venkatesh badrinathan
Ranch Hand

Joined: Aug 03, 2008
Posts: 77
Theank you mario
Jamie MacDonald
Greenhorn

Joined: May 17, 2008
Posts: 20
Yay Mario--first post!

If you look at the section entitled parseXxx() and valueOf() 2 pages before the table it shows some more examples of using parseXxx with a radix and also mentions throwing a NumberFormatException if the String argument is not properly formed. The String is not a properly formed number if it contains any character that does not comprise a number of the specified radix (or a decimal--base 10--number is no radix is specified). So a string containing the letter "z" would always cause the exception, and a string with a "3" would cause the exception if the radix were 2 since binary numbers contain only "0" and "1".
Mario Razec
Greenhorn

Joined: Aug 01, 2008
Posts: 17
hi all,
My first post, now my second post =)
I was read javaranch but never post.
Interesting explanation Jamie...
Thanks a lot..

see ya
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wrapper conversion methods..