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 primitive conversion 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 "primitive conversion" Watch "primitive conversion" New topic
Author

primitive conversion

Veena Pointi
Ranch Hand

Joined: Jun 20, 2002
Posts: 442
In the method
public static Integer valueOf(String s) throws NumberFormatException
Throws:
NumberFormatException - if the string cannot be parsed as an integer.
what is meant by parsed?Does it mean if it can not be convertible to int?
Veena


SCJP1.4
"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
Dave Johnson
Ranch Hand

Joined: May 25, 2003
Posts: 111
Parse literally means to analyze. In this case this method takes a String as an arguement which can used to create a primitive type. i.e. int etc.
Mani Ram
Ranch Hand

Joined: Mar 11, 2002
Posts: 1140
"Represent" will be a more proper word than "convertible"
Say when the String passed is "100", there won't be any trouble because it can be represented as an integer (100).
But if the input String is "abc", which cannot be represented as an integer then the exception is thrown.


Mani
Quaerendo Invenietis
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Again, at run time if string contains an integer value which is beyond int limits, exception will be thrown.
Veena Pointi
Ranch Hand

Joined: Jun 20, 2002
Posts: 442
if it is meaning representing an int,if we give 0x16(which is hexadecimal integer representation) as an argument it gives compiler error
Veena
Steve Lovelace
Ranch Hand

Joined: Sep 03, 2003
Posts: 125
If you do this:
Float f = new Float(0x16);
it works just fine. That's the same as:
Float f = new Float(22);
0x16 and 22 are integer literals representing the same number. However if you try this:
Float f = new Float("0x16");
you will get a NumberFormatException. The string "0x16" is not an integer literal, it is a string representation of an integer literal. The jvm routine which converts strings to floating point values is happy to take "22" or "22f" or "22e0", but for whatever reason doesn't seem to like representations of literals in radices other than 10.


The Inner that is named is not the true Inner.
Edwin Keeton
Ranch Hand

Joined: Jul 10, 2002
Posts: 214

Actually the string representation of 0x16 is "16".
works just fine as does where in both cases the second parameter is the radix.
But, fortunately, valueOf() and parseXXX() are not overloaded in Float and Double. (Think of how maddening it would be to convert the decimal part of the number to a different radix.)
The "String" constructors of all the wrapper classes interpret the parameter as radix 10.


SCJP, SCWCD
Veena Pointi
Ranch Hand

Joined: Jun 20, 2002
Posts: 442
Originally posted by Edwin Keeton:
Actually the string representation of 0x16 is "16".
works just fine as does where in both cases the second parameter is the radix.
But, fortunately, valueOf() and parseXXX() are not overloaded in Float and Double. (Think of how maddening it would be to convert the decimal part of the number to a different radix.)
The "String" constructors of all the wrapper classes interpret the parameter as radix 10.

Thanks Edwin.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: primitive conversion