Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

learning java

Duane Morin wrote:
> * I have a list of several million strings, but I know that there are only 
> about 100k unique ones.  I want to make myself a frequency table that 
> tells me how often each string occurred.  Write me a data structure to do 
> it.  Everybody makes a hashmap, which is fine, but most people end up 
> creating several million Integer objects when it can be done by only 
> creating 100k.
> If I ask somebody to write code it is always for a 'toy' problem that can 
> be easily encapsulated and written in like 10 minutes.  It's always 
> interesting to see people who claim to write Java every day get flustered 
> over some pretty basic stuff.  And I'm not talking about memorizing the 
> API (although I'd like to think that everybody knows how to get/put a 
> hashmap), I"m talking about Java syntax like this:
> 	boolean table[arr.length];
> 	for (int i =0; i < table.length; i++) {	
> 		table[i] = false;
> 	}
> That's wrong and redundant, btw. :)

I'd probably figure that the person who made these two mistakes spent 
too much time writing C or C++, and not enough writing Java. If they did 
well on all the other tests, I'd be inclined to give them the benefit of 
the doubt, especially if I were hiring for a long-term position (where 
the programmer would get into the Java groove soon enough) rather than 
something where I need him to be productive yesterday (a good situation 
to avoid, but it does happen).

In the first example, I assume that what you're getting at is that you 
should change the value of the Integer objects in the hashmap rather 
than creating new ones. It's not an issue in C, because your hash table 
would contain ints (primitive types) rather than objects.

It's also symptomatic of a failing of the current state of computer 
education; nobody teaches anything about low-level efficiency issues any 
more. I don't think a typical CS101 or CS102 class (which is taught in 
Java at most schools now) would ever mention the issue in your example. 
Things were very different when I first learned to program; but then, 
the first computer I used was a million times slower than a current 
state-of-the-art desktop PC. (Yes, just about literally. It was an IBM 
1620, which could hit a peak execution rate of about 6,000 instructions 
per second, and its average was considerably lower than that.)

The second example is nearly correct C++ (except that the Java syntax 
for finding the length of the array has been used); it would also work 
in C if boolean and false have been defined somewhere, as they often 
are. In Java, of course, you have to use new to create arrays, and you 
don't have to bother initializing them to false because Java already 
does it for you.

BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!

Boston Linux & Unix /