learning java

Duane Morin dmorin at lear.morinfamily.com
Thu Apr 29 22:20:23 EDT 2004


On Fri, 30 Apr 2004, Derek Martin wrote:
> Isn't XML seperate and distinct from Java?  What's one got to do with
> the other?  Presumably the applications you're working with make a lot
> of use of XML?  If so, would you consider hiring someone with no
> experience working with XML?

Sure.  That wasn't intended to be a Java specific question, although the 
two do often come hand in hand.  I'll only ask XML questions if people 
list XML as a skill.  And absence of XML experience won't cost you the 
job.

> go.  But this strikes me as mainly an academic problem... While I've
> written many segments of code to test various bits, I've never
> actually come across a need to count those that are set.  Is there a
> practical use for this problem?

Dunno.  You're right, it's an academic problem.  It was asked of me when 
I was hired and, like college frat hazing, I am passing the love onto the 
next generation :).

> I'm also curious about what some of the other suggested solutions were...  

Mostly variations on the bit mask idea.  It's interesting to see how 
people try to make a bitmask.  Somebody recently tried to use logarithms
to do it.  Some folks shrug and say that since the primitive is of a 
fixed length then don't even bother with a loop, just unroll it and have
32  "if (x & (1<<y) != 0) total+=1;" lines, changing Y.

Some folks create bit masks of size N which allow you to count the bits
at in M/N passes, instead of M, which is neat.  For instance if I said
that the problem was to count bits in a byte array then a good solution
might be to just create a 256 entry bitmask table of all the 8 bit
combinations, then just look up each byte's value in the table.

> > creating several million Integer objects when it can be done by only 
> > creating 100k.
> Not knowing Java, I couldn't write the code to do it; but the obvious
> solution seems to be to create a hash with the string as a key, and
> the frequency would be the value.

The trick is that you can't store primitives in collections in Java, so 
people end up having to create a new Integer object just to increment the 
value they already stored.  Thus, a new Integer for every entry in the
original array, rather than just a new integer  only when you create a new
entry in the hash table.

> > * Crawl all the HREFs out of a given HTML file.
> Here I would definitely apply the Google defense...  ;-)

Aw come on, a little Perl and it wouldn't be that hard.  Actually when 
this question is asked the real interesting bit is to ask how long the 
candidate thinks it would take.  If they say 2 weeks, hmmmm.....

> I'm not trying to pick on you or start a flame war, but I'm curious
> about your reasoning for asking this particular question.  LRU caches
> seem particularly of interest to people writing database code or
> operating system code, and not much else.  [I would argue that the
> cache for a web browser is a kind of database, even if the web browser
> is very different from a DBMS package.] 

And, truthfully, I haven't asked this question, another one of the guys 
here has.  It's quite common to ask programming questions using real 
problems that the team is dealing with.  We have an admitted bias toward
candidates with a formal CS education, for good or bad.  So somebody
should at least know what LRU means, for instance, and be able to take a
stab and how you'd implement one.  It by no means has to be perfect.  It's
more of a "Let me listen to how you think...." problem.

Duane





More information about the Discuss mailing list