About Question enthuware.ocajp.i.v8.2.1430 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ElizabethCM
Posts: 29
Joined: Sun Apr 05, 2015 11:26 am
Contact:

About Question enthuware.ocajp.i.v8.2.1430 :

Post by ElizabethCM »

Hi,

The java.time.temporal.TemporalAdjusters are not mentioned in the book. Do you think they will be included in the material?
It's not bad to know them...but there are a lot of new things to remember about the dates...

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1430 :

Post by admin »

Only one person reported getting a simple question on it. So I would say if you just go through our questions on this, you will be fine. No need to read further.
If you like our products and services, please help us by posting your review here.

ElizabethCM
Posts: 29
Joined: Sun Apr 05, 2015 11:26 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1430 :

Post by ElizabethCM »

Hi,

Thank you for the quick answer. I will go through the exercises again.
I am struggling with the following code which appears in the book at page 149 (at least this is the page using Kindle Cloud Reader)
Could you please have a look at it?

DateTimeFormatter f = DateTimeFormatter.ofPattern("MM dd YYYY");
LocalDate date1 = LocalDate.parse("01 02 2015", f);
System.out.println(date1);

It gives the following error:
Exception in thread "main" java.time.format.DateTimeParseException: Text '01 02 2015' could not be parsed: Unable to obtain LocalDate from TemporalAccessor: {WeekBasedYear[WeekFields[SUNDAY,1]]=2015, MonthOfYear=1, DayOfMonth=2},ISO of type java.time.format.Parsed
at java.time.format.DateTimeFormatter.createError(Unknown Source)
at java.time.format.DateTimeFormatter.parse(Unknown Source)
at java.time.LocalDate.parse(Unknown Source)
at date_time.DateTimeFormat.main(DateTimeFormat.java:43)
Caused by: java.time.DateTimeException: Unable to obtain LocalDate from TemporalAccessor: {WeekBasedYear[WeekFields[SUNDAY,1]]=2015, MonthOfYear=1, DayOfMonth=2},ISO of type java.time.format.Parsed
at java.time.LocalDate.from(Unknown Source)
at java.time.LocalDate$$Lambda$14/1595428806.queryFrom(Unknown Source)
at java.time.format.Parsed.query(Unknown Source)
... 3 more

Do you have any idea why? Thanks

PS: I did not know if for questions like this (related only to a certain exercise by topic) I should start a new topic on the forum or just write here. Thanks

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1430 :

Post by admin »

Your formatter is for date+time but you are trying to parse a string that contains only date.
If you like our products and services, please help us by posting your review here.

ElizabethCM
Posts: 29
Joined: Sun Apr 05, 2015 11:26 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1430 :

Post by ElizabethCM »

Hi,

Thank you, I did not realize that :)
I'll try again using only the date formatter.

olograph
Posts: 6
Joined: Mon Feb 01, 2016 3:13 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1430 :

Post by olograph »

Only one person reported getting a simple question on it.
Is this person real, 'cause I rather not learn on something out-of-scope that is as captivating as this,
especially at exam 6 of 7, having a TON of things currently in mind.

If you'd say it's one person out of 3000, I'd skip this topic so fast the page will have tire fire on it.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1430 :

Post by admin »

olograph wrote:
Only one person reported getting a simple question on it.
Is this person real, '
The person is certainly real.
cause I rather not learn on something out-of-scope that is as captivating as this,
especially at exam 6 of 7, having a TON of things currently in mind.
Sure, that is a decision that you should make based on your bandwidth.
If you'd say it's one person out of 3000, I'd skip this topic so fast the page will have tire fire on it.
You can skip it but if I were you, I would spend may be about 10-15 minutes on it.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

hsiaok
Posts: 7
Joined: Tue Aug 22, 2017 11:13 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1430 :

Post by hsiaok »

The question is :
You want to print the date that represents upcoming tuesday from now even if the current day is a tuesday. Which of the following lines of code accomplishe(s) this?

Why is it using System.out.println(LocalDate.now().with(TemporalAdjusters.next(DayOfWeek.TUESDAY)));

Should it be
System.out.println(LocalDate.now().with(TemporalAdjusters.nextOrSame(DayOfWeek.TUESDAY))); ? because should return today if today is Tuesday ?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1430 :

Post by admin »

No, the problem statement want to print the next Tuesday (not today even if today is a tuesday).
If you like our products and services, please help us by posting your review here.

JuergGogo
Posts: 28
Joined: Mon Sep 25, 2017 8:16 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1430 :

Post by JuergGogo »

I am struggling with the following code which appears in the book at page 149 (at least this is the page using Kindle Cloud Reader)
Could you please have a look at it?

DateTimeFormatter f = DateTimeFormatter.ofPattern("MM dd YYYY");
LocalDate date1 = LocalDate.parse("01 02 2015", f);
System.out.println(date1);
Your formatter is for date+time but you are trying to parse a string that contains only date.

Code: Select all

import java.time.*;
import java.time.format.*;

public class TestClass{
  public static void main(String[] args) {
      
      // DateTimeFormatter f = DateTimeFormatter.ofPattern("MM dd YYYY"); //--> DateTimeParseException
      DateTimeFormatter f = DateTimeFormatter.ofPattern("MM dd yyyy");
      LocalDate date1 = LocalDate.parse("01 02 2015", f );
      
      System.out.println( date1 );
  }
}
"YYYY" in uppercase isn't working: Y = week-based-year
"yyyy" in lowercase is the correct one for parsing above String: y = year-of-era

flex567
Posts: 202
Joined: Mon Apr 02, 2018 8:40 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1430 :

Post by flex567 »

Are TemporalAdjusters relevant for the exam? The answer about this is 4 years old.
Have there been any recent reports of people getting it?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1430 :

Post by admin »

No, but I would still go though the information given in this question. You might be the lucky/unlucky one who gets that one question.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 43 guests