Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question from mock test, couldnt understand

 
Sham Grandhe
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai friends,
The question given below was from the Marcus Green mock test1. iam unable to get the question, plz explain it.
Which of the following most closely describes a bitset collection?
1) A class that contains groups of unique sequences of bits
2) A method for flipping individual bits in instance of a primitive type
3) An array of boolean primitives that indicate zeros or ones
4) A collection for storing bits as on-off information, like a vector of bit

thanking you
shyam
 
Tushar Gorde
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer is 1.
 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sets have only unique values, no duplicates...
Davy
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, but BitSet is a class left over from Java 1.0 and does not implement the Set interface. It is really more like a BitVector - just one more example of naming confusion created as Java grew. Therefore, answer 3 is correct.
Simply looking at the JavaDocs for java.util.BitSet would have revealed this. You really should make a habit of it.
Bill
 
Don Wood
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question threw me too. It smells like a set but isn't one. How annoying.
But there is another odd thing in answer three:

3) An array of boolean primitives that indicate zeros or ones

As Bill suggested, I looked BitSet up in JavaDoc and it says

Each component of the bit set has a boolean value.

Now we all know that you cannot assign either a zero or a one to a boolean. So anwser three still seems a bit off. In defense of the wording, the class has methods that set, flip and clear bits which sounds more like zeroes and ones than booleans.
Another confusing detail:
JavaDoc says "This class implements a vector of bits...". This is not to be confused with java.util.Vector which takes objects, not primitives.
So BitSet is a vector of bits that is neither a Set nor a Vector. As a language evolves you often see odd quirks like this. Even Java has its share.
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After having read the BitSet doc, I'd have chosen 4), without much hesitation.
Regards,
Phil.
 
Bert Bates
author
Sheriff
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't gotten to be "the focus police" for a while
The exam creators didn't consider BitSet to be part of the "collections framework" as it doesn't implement Collection, Set, List, or Map. So you can relax, and not worry about BitSets for the exam. If, on the other hand, you're goal is to memorize the entire API, then BitSet is a card carrying member
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic