Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS 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
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

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

 
Ranch Hand
Posts: 145
4
Hibernate Spring Java
  • 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 ??

 
Ranch Hand
Posts: 41
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: 145
4
Hibernate Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you So much Dóra Takács for your clear explanation.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • 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: 41
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic