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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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
 
 
subject: primitive datatypes