Question enthuware.ocpjp.v7.2.1192:

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

Moderator: admin

Post Reply
zhajikun
Posts: 2
Joined: Mon Jun 13, 2016 10:09 am
Contact:

Question enthuware.ocpjp.v7.2.1192:

Post by zhajikun »

How will you initialize a SimpleDateFormat object so that the following code will print the full text time zone of the given date?

System.out.println(sdf.format(new Date()));

A. SimpleDateFormat sdf = new SimpleDateFormat("tttt", Locale.FRANCE);

B. SimpleDateFormat sdf = new SimpleDateFormat("T", Locale.FRANCE);

C. SimpleDateFormat sdf = new SimpleDateFormat("z", Locale.FRANCE);

D. SimpleDateFormat sdf = new SimpleDateFormat("zzzz", Locale.FRANCE);

E. SimpleDateFormat sdf = new SimpleDateFormat("XXX", Locale.FRANCE);

The given answer is D, however, when I type in D in netbeans, it give me an compile error.

C is correct according to Netbeans. It prints out "CDT".

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

Re: Question enthuware.ocpjp.v7.2.1192:

Post by admin »

Please try using command line. Option D is correct.

HTH,
Paul.

dominik.jenik
Posts: 2
Joined: Tue Jul 04, 2017 4:00 am
Contact:

Question enthuware.ocpjp.v7.2.1192:

Post by dominik.jenik »

In the explanation note under answer of question states:
Remember that if the number of pattern letters is 4 or more, the full form is used;
When I try this:

Code: Select all

System.out.println(new SimpleDateFormat("XXX", Locale.FRANCE).format(new Date()));
everything looks good, but when I try this:

Code: Select all

System.out.println(new SimpleDateFormat("XXXX", Locale.FRANCE).format(new Date()));
exception occurs. This looks like "hidden feature" of Java compiler.

Code: Select all

Exception in thread "main" java.lang.IllegalArgumentException: invalid ISO 8601 format: length=4
	at java.text.SimpleDateFormat.encode(SimpleDateFormat.java:878)
	at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:863)
	at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:659)
	at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:585)
	at Runner.main(Runner.java:30)

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

Re: Question enthuware.ocpjp.v7.2.1192:

Post by admin »

That explanation is for option 4. i.e. zzzz not XXXX.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 10 guests