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".
			
			
									
									
						Question enthuware.ocpjp.v7.2.1192:
Moderator: admin
- 
				zhajikun
 - Posts: 2
 - Joined: Mon Jun 13, 2016 10:09 am
 - Contact:
 
- 
				admin
 - Site Admin
 - Posts: 10443
 - Joined: Fri Sep 10, 2010 9:26 pm
 - Contact:
 
Re: Question enthuware.ocpjp.v7.2.1192:
Please try using command line. Option D is correct.
HTH,
Paul.
			
			
									
									
						HTH,
Paul.
- 
				dominik.jenik
 - Posts: 2
 - Joined: Tue Jul 04, 2017 4:00 am
 - Contact:
 
Question enthuware.ocpjp.v7.2.1192:
In the explanation note under answer of question states: 
everything looks good, but when I try this:
exception occurs. This looks like "hidden feature" of Java compiler.
			
			
									
									
						When I try this:Remember that if the number of pattern letters is 4 or more, the full form is used;
Code: Select all
System.out.println(new SimpleDateFormat("XXX", Locale.FRANCE).format(new Date()));Code: Select all
System.out.println(new SimpleDateFormat("XXXX", Locale.FRANCE).format(new Date()));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: 10443
 - Joined: Fri Sep 10, 2010 9:26 pm
 - Contact:
 
Re: Question enthuware.ocpjp.v7.2.1192:
That explanation is for option 4. i.e. zzzz not XXXX.
			
			
									
									
						Who is online
Users browsing this forum: Merlewaigo and 24 guests