• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

primitive datatypes

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Aneeta Srini
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot ! I now understand
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic