This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

K & B OCA/OCP Java SE 7 Programmer I and II Study guide's interactive quizes  RSS feed

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given:
SimpleDateFormat f1 = new SimpleDateFormat("MM dd yyyy");
SimpleDateFormat f2 = new SimpleDateFormat("MM dd yyyy");
DateFormat f3 = DateFormat.getDateInstance(DateFormat.SHORT);
DateFormat f4 = DateFormat.getDateInstance(DateFormat.SHORT);


Which of the following are true? (choose all that apply)
A) f1 == f2 will always return true
B) f1 == f2 will never return true
C) f3 == f4 always returns true DateFormat is a factory
D) f3 == f4 always returns true DateFormat is a singleton
E) f3 == f4 never returns true DateFormat is a factory
F) f3 == f4 never returns true DateFormat is a singleton


I think this quiz is incorrect one.My answers are BE.But correct answers are BCE..How f3 == f4 can always be true on C answer.Please help me about this quiz.
 
Author
Ranch Hand
Posts: 183
9
Java Linux Netbeans IDE Scala Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(I don't have the book, but don't tell Kathy and Bert! Consequently, I can't tell if what you documented here is an accurate copy of what's in the book

That said:

I think the real reason that B, C, E cannot be a correct answer is that, C and E exactly contradict one another, right? C says "f3==f4 always true" and E says "f3==f4 always false"

However, in general it's quite common to use Factory methods to return the same object. That, after all, is what a Singleton design pattern does. However, there's also no obligation on a factory to do that; it would depend on the scenario.

Also, "sharing" immutable objects with identical contents is a sensible approach, so C would be entirely reasonable from that perspective too.

On the other hand, there's nothing in the API docs describing this sharing or pooliing behavior, and further, when I run the code, I do not get the same object returned.

So, provided you copied the question accurately then I agree that C is not a correct answer, and I also believe that C and E are contradictory.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can confirm it is an accurate copy. Just bumped in that question.
However, I think the right answers are B and D
B, because for two distinct objects '==' will never return true
D, because a singleton always returns the same object
And, like Simon said, factory can return every time the same object or the new object. So, answers C and E are are false
 
Simon Roberts
Author
Ranch Hand
Posts: 183
9
Java Linux Netbeans IDE Scala Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I disagree with D because:

a) I ran the code, and it comes up false
b) I read the docs, and found no requirement for the getDateInstance method (which is, in the broadest sense a factory) to behave as a singleton when given the same parameter.

By the way, it's potentially important, particularly for an exam, to distinguish behavior required by specification from behavior that happens to occur in a given implementation. But in this case, I believe that both scenarios speak against D.

Unless, perhaps you can show the specification that it should be true, in which case, either my test code is broken (though it's simple enough to be "obviously correct" -- no, I don't believe that ) or the implementation is...
 
Denis Kipchakbaev
Greenhorn
Posts: 12
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simon, I'm completely sure that your test is alright and your answer made me to rethink why I choose D. And then I've found a little inconsistency in Javid's post. The actual answer options are:

A) f1 == f2 will always return true
B) f1 == f2 will never return true
C) IF f3 == f4 always returns true, DateFormat is a factory
D) IF f3 == f4 always returns true, DateFormat is a singleton
E) IF f3 == f4 never returns true, DateFormat is a factory
F) IF f3 == f4 never returns true, DateFormat is a singleton

So I think that the question not about a real DateFormat, but about some hypothetical situation. So I still choose B, D
What do you think?
 
Simon Roberts
Author
Ranch Hand
Posts: 183
9
Java Linux Netbeans IDE Scala Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh boy! That's a really important difference! This serves, among other things to remind us all of how absolutely critical it is to read test questions carefully

Good call!
 
Javid Azimli
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The actual copy below:

 
Simon Roberts
Author
Ranch Hand
Posts: 183
9
Java Linux Netbeans IDE Scala Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, yeah, the wording is pretty weird, for sure.

The method is a factory, because it returns an object built, or obtained, based on a parameter (it cannot be a singleton, because singletons aren't parameterized.) But the whole "If blah , blah" is really strange, in C and E, it's irrelevant information I would say.

By the way, questions written by "normal people", which includes authors are subject to occasional errors. The real exams are of course perfect. What, they're not? No, probably not, but they're extensively reviewed, by many people, over time, even before they go to a beta test. So, in general, it's probably best to ignore the possibility of a real, mark-carrying, question, being wrong.

On that topic, know that not all questions are scored. Some are beta test items that are there for the question to be evaluated, rather than the candidate. All the more reason to just get on with it, give your best answer, and move on. Never waste a lot of time on one question in a real exam.
 
Javid Azimli
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah weird.But I think that BE correct ones.C can't be true.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!