This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes primitive datatypes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "primitive datatypes" Watch "primitive datatypes" New topic
Author

primitive datatypes

Aneeta Srini
Greenhorn

Joined: Jul 23, 2002
Posts: 16
I found this in Mughal's book.

He says that we need to ensure that the values that are multiplied really are multiplied using long datatypes, not multiplied as int datatypes
and later converted to long. The L suffix on the 1000L integer literal ensures this.
My question is what difference does it make if they they are multiplied as int datatypes and later converted to long??
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
If you compute 150000000 * 1000 as integer the result will be bigger than Integer.MAX_VALUE.
Actually if you compile the code and run it, you can see that mFromSun yields -323855360
However, if you compute the value as a long you get the correct result...


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Aneeta Srini
Greenhorn

Joined: Jul 23, 2002
Posts: 16
Thanks a lot ! I now understand
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: primitive datatypes
 
Similar Threads
Displaying a Time in Different Time Zone
Finding Elapsed Time
Does parenthesis makes difference on calculation?
convert unix milli seconds to java date :-)
problem with "Expires" header