aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
Does parenthesis makes difference on calculation?
problem with "Expires" header
convert unix milli seconds to java date :-)
Displaying a Time in Different Time Zone
Finding Elapsed Time