This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes java rule round up #113 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "java rule round up #113" Watch "java rule round up #113" New topic
Author

java rule round up #113

Jeroen van der Velden
Greenhorn

Joined: Apr 07, 2003
Posts: 10
Can somebody explain to me why the following code compiles and runs:
double x; x=24.0/0;
The answer says it will compile and run because floating point nummers don't produce a divide-by-zero ArithmeticException. They will give a result which is Not a Number value. But for me it looks like 24.0 is a double and not a floating point number because it has no f attached to it.


Jeroen.<br />SCJP 1.4
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
A double primitive is also a floating point number. By default, a floating point value is a double. If you append a 'f' after the number, it becomes a float value.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Reshma Shanbhag
Ranch Hand

Joined: Sep 17, 2002
Posts: 202
Hi Jeroen,
Welcome to Javaranch .
Both float(32 bits long) and double(64 bits long) are floating point values (that is both are decimal values) with different ranges. Default floating point value is 'double'.
For example
float f = 12.0, this will give a compile time as error as '12.0' denotes a double value.to make this statement compile we need to modify it as float f = 12.0F.
So the above answer mentioned is right.
reshma


SCJP 1.4, SCWCD 1.4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java rule round up #113
 
Similar Threads
Floating Point Number and dividebyzero arithmatic exception
Question on float variables
Rules roundup #113
Rules Roundup Q 113 Answer Nitpick
Number of days between the 2 given dates.