wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Double Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Double" Watch "Double" New topic
Author

Double

Sridhar Srinivasan
Ranch Hand

Joined: Nov 07, 2003
Posts: 117
Hi!
The double data type can accept an int rite?
double d=0x10
Why the following gives a run time exception?Can anybody pl explain?Thanks.
Double d1 = new Double("0x10");
[ May 22, 2004: Message edited by: Barry Gaunt ]

Software_guy
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
The constructor that accepts string for wrapper classes is more restrictive from the one that accepts primitives. That is why you can't pass a hex string value.

Take this for an example:

Double d1 = new Double("010");
d1.doubleValue(); // print the result

is treated as an integer number of base 10, the leading zero (which represents that the number is octal) is simply ignored. So the value stored in 'd1' is 10, and not 12 as you might expect.


- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
For this kind of question it's a good idea to look at the Java 1.4.2 API. It's a much better source of information than one's own intuition.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Double