• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

potential Errata page 139 (Java OCA 8 Programmer I Study Guide, Sybex)

 
Ricard Nàcher Roig
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the book at page number 139, just above the square highlighted text, there is the following text:

"
2015-01-20
12:45:18.401
2015-01-20T12:45:18.401

The key is to notice the type of information in the output. The first one contains only a
date and no time. The second contains only a time and no date. This time displays hours,
minutes, seconds, and nanoseconds. The third contains both date and time. Java uses T to
separate the date and time when converting LocalDateTime to a String"

I think that time information show milliseconds rather than nanoseconds. Maybe the authors wanted to highlight that LocalTime has nanosecond precision.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ricard Nàcher Roig,

First of all, a warm welcome to CodeRanch!

Ricard Nàcher Roig wrote:I think that time information show milliseconds rather that nanoseconds.

I think the book is spot-on here!

If you have a look at the javadoc of the DateTimeFormatter class, you can read this
DateTimeFormatter wrote:Fraction: Outputs the nano-of-second field as a fraction-of-second. The nano-of-second value has nine digits, thus the count of pattern letters is from 1 to 9. If it is less than 9, then the nano-of-second value is truncated, with only the most significant digits being output.
So it's clearly the (truncated) nano-of-second value.

And if you look at the API of e.g. the LocalDateTime class, you'll notice methods like minusNanos(long nanos), plusNanos(long nanos) and withNano(int nanoOfSecond), but no equivalent methods for milliseconds. And you'll notice (of course) the same with the LocalTime class.

Hope it helps!
Kind regards,
Roel
 
Ricard Nàcher Roig
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first of all thanks for your reply.

I was trying to notice that, in my opinion, the example is not the right one. I mean that if someone tell me that "2015-01-20T12:45:18.401" contains nanoseconds and there is no other example with nanoseconds, I would think that this is a mistake, although it gets explained in the following page. I would prefer to have also an example with nanoseconds, let's say "2015-01-20T12:45:18.401000123" just there and add some comment explaining the truncation process in that paragraph. Actually, I mean that I get confused while reading that part, I miss an example with nano-seconds or a note about output truncation.

best regards!
Ricard

regards.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ricard Nàcher Roig wrote:I would prefer to have also an example with nanoseconds, let's say "2015-01-20T12:45:18.401000123" just there and add some comment explaining the truncation process in that paragraph.

But it is an example with nanoseconds, but the nanoseconds appear to be zero. According to the toString() method of the LocalTime class, there are different possible formats and the shortest format that outputs the full value will be used, all ommitted parts are implied to be zero. So the value 12:45:18.401 is actually 12:45:18.401000000.
LocalTime wrote: The output will be one of the following ISO-8601 formats:
* HH:mm
* HH:mm:ss
* HH:mm:ss.SSS
* HH:mm:ss.SSSSSS
* HH:mm:ss.SSSSSSSSS
The format used will be the shortest that outputs the full value of the time where the omitted parts are implied to be zero.


Ricard Nàcher Roig wrote:Actually, I mean that I get confused while reading that part, I miss an example with nano-seconds or a note about output truncation.

Although it's not really an errata item, it might be taken into consideration as an improvement for a next version of the study guide.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic