Hello, I am trying to prepare for an interview code quiz. I do not have the details of the problem, but they have given me a vague outline. They have left me to prepare as I see fit, so I decided it would be fair to ping you guys and girls for suggestions.
I will be given two hours to develop a program in Java. The program will parse text from a file (or other source) and analyse it somehow. They have suggested that I familiarize myself with java.io.Reader, standard data structures, and concurrency mechanisms.
I have never hired anyone, or interviewed anyone, or even been interviewed in the past 5 years, so take what I say with a grain of salt.
Personally, I'm not sure I'd care if you ever wrote a single line of actual java. A lot of the times, they are interested in how you approach the problem, not the specific details of the implementation.
Did you sit down and start writing code before you even finished reading the problem?
What assumptions did you make?
Did you get clarification?
Did you ask questions about what was wanted or needed?
Did you sit and think about the problem first? Write out some ideas of what to watch out for? revise your design a few times?
Assuming this doesn't take up your time, and you actually get to writing code...
Did you follow proper coding conventions?
Did you comment your code?
Did you compile frequently, or did you write 2000 lines of code and never compile once?
Did you document your assumptions?
Never ascribe to malice that which can be adequately explained by stupidity.
Joined: Jun 15, 2009
Thanks for the fast feedback, Joanne and Fred. It is greatly appreciated.
Fred: That is somewhat reassuring. I will keep this in mind.
Joanne: I know a bit about concurrency, but I am trying to anticipate how it might apply to this problem. I suppose concurrency could be used to read and "analyse" multiple files at once, for example.
Joined: May 31, 2007
It could be anything, but here are a few things to refresh on:
Learn about the concurrent data structures like ConcurrentHashMap, CopyOnWrite Lists and Sets, etc.
You will also have to learn about the communication between a number of threads using wait()/ notify(). For example, you may have 2 files. You will have to create 2 threads to read from each file and write to a pipe, where a third thread will listen to and add the numbers together or evaluates if the sum is a multiple of 2 and write to another text file. So, learn about how threads communicate with each other. I have some examples on my blog.
Learn about thread synchronization and volatile keyword.
Also, look at the ExecutorService framework to create thread pools if you have time.
While you may not care if the candidate ever wrote a line of Java, this company clearly does since they suggested familiarizing with java.io.Reader. That statement is like a gift. Not knowing those Java APIs at the interview seems foolish.
fair point. I guess my suggestions are more generalized, but yes, if they explicitly state "learn about X, Y and Z", then by all means, familiarize yourself with X, Y and Z.
Joined: Apr 16, 2008
Is the candidate going to be provided with a working IDE, Java compiler, JavaDocs, keyboard, mouse and monitor?
Or, will the candidate be required to write the program from memory using a few sheets of paper and a pencil?
Joined: Jun 15, 2009
Thanks for the advice, everyone. It helped. I wrote the exam remotely, so I had access to whatever resources I wanted. I used Eclipse and a web browser. I emailed my program in when I finished. Here are some of the data structures and methods I used:
My concurrency knowledge was not up to snuff, but they listed it as an "extended objective", so I hope what I wrote was enough to show them I am serious.
Joined: Apr 19, 2005
you can use hashmap<string,integer> to count word frequency. But if the file is huge and most of the words are distinct, you ll run out of memory. One way to solve the problem is to write the map to a file once it reaches certain size e.g.1000. Empty the map and continue to process the file. At the end, you ll need to merge what you have in the map with the file.
Joined: Oct 13, 2005
I wouldn’t call 1000 huge. Don’t worry about memory until your Map has millions of entry pairs.
Joined: Jun 15, 2009
By the beard of Zeus! I'm being flown out for a face-to-face interview.