Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I need explanation about two dates questions (Java OCA 8 Programmer I Study Guide, Sybex)

 
Narayana Bojja
Ranch Hand
Posts: 135
4
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
32. What is the output of the following code?

A. 3/7/14 11:22 AM
B. 5/10/15 11:22 AM
C. 3/7/14
D. 5/10/15
E. 11:22 AM
F. The code does not compile.
G. A runtime exception is thrown.

Prints 11:22 AM .

33. What is the output of the following code?

A. 5/9/13 11:22 AM
B. 5/10/13 11:22 AM
C. 5/9/14
D. 5/10/14
E. The code does not compile.
F. A runtime exception is thrown.

Prints  5/10/13 11:22 AM


Two methods signatures are

public String format(DateTimeFormatter formatter) // in LocalDate class method

public String format(TemporalAccessor temporal) // in DateTimeFormatter class method

format method in Local Date class internally calls DateTimeFormatter  format method .

why format method in LocalDate class prints only time ???

Could anyone clarify this doubt ??

 
Dóra Takács
Ranch Hand
Posts: 33
4
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

And the answer to your question is in this row:

Let me edit it a bit further so you can see what method we are using:
DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT);

We are adding a format to our LocalDateTime that only formats the Time part, thus the result will output only time.
What do you think would happen if we used this instead?
 
Narayana Bojja
Ranch Hand
Posts: 135
4
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you So much Dóra Takács for your clear explanation.
 
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
Narayana Bojja wrote:Thank you So much Dóra Takács for your clear explanation.

That's indeed a very nice and clear explanation, Dóra Have a cow!

It's time for another (free) pop quiz question. What will be the output of the following code snippet?

Hope it helps!
Kind regards,
Roel
 
Dóra Takács
Ranch Hand
Posts: 33
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeey I' got a cow \o/ Thank you Roel!

And I can barely pull myself back from answering that miniquiz
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic