Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interview code quiz preparation

 
David Sharpe
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 3742
    16
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    fred rosenberger
    lowercase baba
    Bartender
    Posts: 12122
    30
    Chrome Java Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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?

     
    David Sharpe
    Ranch Hand
    Posts: 36
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 3387
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    Jeanne Boyarsky
    author & internet detective
    Marshal
    Posts: 34396
    346
    Eclipse IDE Java VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    fred rosenberger
    lowercase baba
    Bartender
    Posts: 12122
    30
    Chrome Java Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 2187
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 36
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 206
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 48921
    58
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I wouldn’t call 1000 huge. Don’t worry about memory until your Map has millions of entry pairs.
     
    David Sharpe
    Ranch Hand
    Posts: 36
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    By the beard of Zeus! I'm being flown out for a face-to-face interview.
     
    Campbell Ritchie
    Sheriff
    Posts: 48921
    58
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Good luck!
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic