aspose file tools*
The moose likes Jobs Discussion and the fly likes Interview code quiz preparation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Careers » Jobs Discussion
Bookmark "Interview code quiz preparation" Watch "Interview code quiz preparation" New topic
Author

Interview code quiz preparation

David Sharpe
Ranch Hand

Joined: Jun 15, 2009
Posts: 32
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.

To prepare, I reviewed the Java Practices website entries for parsing text and reading and writing text files. I am wondering what else I can do to prepare.

Does anyone have any ideas how
  • I might be expected to "analyse" the text? Maybe something simple like counting word frequency?
  • Concurrency might be involved?
  • Joanne Neal
    Rancher

    Joined: Aug 05, 2005
    Posts: 3682
        
      16
    David Sharpe wrote:
  • Concurrency might be involved?

  • So maybe learn about concurrency in Java.
    There's a complete lesson about it in the Java tutorial and three separate packages for it in the standard API. That should keep you going for a while.

    Joanne
    fred rosenberger
    lowercase baba
    Bartender

    Joined: Oct 02, 2003
    Posts: 11422
        
      16

    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?


    There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
    David Sharpe
    Ranch Hand

    Joined: Jun 15, 2009
    Posts: 32
    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.
    arulk pillai
    Author
    Ranch Hand

    Joined: May 31, 2007
    Posts: 3223
    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.


    Good luck.


    Java Interview Questions and Answers Blog | Amazon.com profile | Java Interview Books
    Jeanne Boyarsky
    author & internet detective
    Marshal

    Joined: May 26, 2003
    Posts: 30767
        
    156

    Fred,
    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.

    I'd also look at the Scanner class.


    [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
    Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
    fred rosenberger
    lowercase baba
    Bartender

    Joined: Oct 02, 2003
    Posts: 11422
        
      16

    Jeanne,

    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.

    Jimmy Clark
    Ranch Hand

    Joined: Apr 16, 2008
    Posts: 2187
    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?
    David Sharpe
    Ranch Hand

    Joined: Jun 15, 2009
    Posts: 32
    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:

  • java.lang.BufferedReader
  • String.split(String)
  • String.substring(int, int)
  • java.lang.ConcurrentHashMap
  • enum


  • 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.
    vu lee
    Ranch Hand

    Joined: Apr 19, 2005
    Posts: 189
    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.
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 39436
        
      28
    I wouldn’t call 1000 huge. Don’t worry about memory until your Map has millions of entry pairs.
    David Sharpe
    Ranch Hand

    Joined: Jun 15, 2009
    Posts: 32
    By the beard of Zeus! I'm being flown out for a face-to-face interview.
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 39436
        
      28
    Good luck!
     
    Don't get me started about those stupid light bulbs.
     
    subject: Interview code quiz preparation