File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes problem/ failure in question - question is not locale aware (Study Guide) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "problem/ failure in question - question is not locale aware (Study Guide)" Watch "problem/ failure in question - question is not locale aware (Study Guide)" New topic
Author

problem/ failure in question - question is not locale aware (Study Guide)

moritz mueller
Greenhorn

Joined: Jan 21, 2010
Posts: 7
i am in preparation for ocjp and stumbled accross this question (from study Guide 6):
Given:

Which are true? (Choose all that apply.)
A. The output is 987.12345 987.12345
B. The output is 987.12346 987.12345
C. The output is 987.12345 987.123456
D. The output is 987.12346 987.123456
E. The try/catch block is unnecessary
F. The code compiles and runs without exception
G. The invocation of parse() must be placed within a try/catch block

The Problem is that A,B,C,D are locale aware in and will look different in different countries. But the "correct" answers are D,F and G. Does this kind of problem still persist and every must "think2 in US-Locale?
The answer would be correct with: NumberFormat nf = NumberFormat.getInstance(Locale.US);

In Germany the output look like this:
987,12346
987123456

two lines - the second problem with some answers: sometimes line breaks are printed and some times not (there are answers that only differ in those line breaks)

Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
Good Day,

The code runs and prints these "expected" values and I'm in the US -



Regards,
Dan


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
moritz mueller
Greenhorn

Joined: Jan 21, 2010
Posts: 7
And this is the Problem the output is not locale independent. The problem is that this question silently implies that the code runs in a us locale and this is a question from a chapter that checks your knowledge about locale aware code. Other question from other chapters are expressing environment dependent question more precisly: "What are possible outputs", "What are true for locale us" ...
neil walker
Greenhorn

Joined: Jan 24, 2008
Posts: 19
I guess from the answers supplied you've just got to assume that the question isn't testing your ability to know locales but is purely testing your ability to know how and when rounding occurs which will be the same (you'd hope) in most locales that do use full stops.

As for your point about lack of locale, I've just read that chapter again and as typical with authors of an American stance the assumption is you are American too as there's pleny of mention of results without mentioning locale.
moritz mueller
Greenhorn

Joined: Jan 21, 2010
Posts: 7
the problem is that this question is related to the chapter that teaches you about locales and their use (to get instances of Date- and NumberFormat) and it teaches you that the jvm has a default locale based on your location. if this knowledge is taken into account the question or answer is wrong. there are many other question that explicitly set and use other locales.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem/ failure in question - question is not locale aware (Study Guide)