This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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
posted
0
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
posted
0
"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
posted
0
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
posted
0
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
posted
0
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.
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
posted
0
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.