Win a copy of Spark in Action this week in the Open Source Projects forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Error in book version of OCAJP 8?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Chapter 2, page 57. Very bottom of the page.

A double is declared as "double x = 1.21;". But it would not compile without "f" suffixe. Correction should be "double x = 1.21f;".

Is that right?

Thank you,
 
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch Michael.

Michael Migs wrote:A double is declared as "double x = 1.21;". But it would not compile without "f" suffixe. Correction should be "double x = 1.21f;".

Is that right?


Sorry you are incorrect on this point.
Any time you declare a number as double an implicit d is added to the end. So

is actually

And this compiles and run fine.
If you wanted to use a float, which is smaller then a double you need to add in the f

Here is a sample that you can try out

Please provide the book tile and authors when talking about a book as there are many different books out there, thanks.
 
Michael Migs
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Pete,

Thank you for the quick and detailed answer. Sorry about the lack of details on the book. I guess you've found it but just so that it is clear for everyone, the book is "OCA Oracle Certified Associate Java SE 8 Programmer 1" by Jeanne Boyarsky and Scott Selikoff.

Indeed I had missed the part saying that floating-point literals are assumed to be double by default unless suffixed with "f". It makes perfect sense now and I'm glad you made that clear because I would have probably missed that for the exam

 
Pete Letkeman
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm glad that I was able to help you out.
Feel free to ask any Java questions on this site as there are some people who are really well versed in Java and they can most likely help you out.

Good luck with your preparations and if you are wondering what others have used to prepare then go here
https://coderanch.com/wiki/659980/Ocajp-Wall-Fame

One resource that you may want to look into is Enthuware as it will give you over 500 exam like questions on nine different tests and it costs about $10 USD.
 
    Bookmark Topic Watch Topic
  • New Topic