Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning 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
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Sybex 1Z0-815, Chapter 2 - Writing Literals

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my honest opinion, the book should mention the default type when writing literals for decimal numbers: double

Source: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

The book only specifies the default type assumed by the compiler for integer numeric literals (int).
 
Marshal
Posts: 68904
275
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CK: Welcome to the Ranch
 
Cristina Kiss
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again,

Thank you !

I just wanted to point out that in Chapter 2 it is not explained in any way that floating-point numeric literals that appear in a piece of code are interpreted (default to) double.

Furthermore, Chapter 3 refers to this concept, which is a bit misleading:
" As you may remember from Chapter 2, floating-point literals are assumed to be double, unless postfixed with an f, as in 2.1f (Boyarsky, 20191119, p. 89)

Boyarsky, J., Selikoff, S.  (20191119). OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide [VitalSource Bookshelf version].  Retrieved from vbk://9781119584568

Always check citation for accuracy before use.
"

What do you guys think ?

Thanks,
Cristina.
 
author & internet detective
Posts: 39957
804
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Table 2.1 has an example of 123.45f.  Table 2.3  (page 53) has a a table with the default types. It lists 0.0 for both float and double. We intentionally don't cover 0.0f vs 0.0d there because we are trying to illustrate the principle of a floating vs integer type there. And we cover that a smaller type can be stored in a larger type. So looks good to me!
 
What? What, what, what? What what tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic