Coding interview with Java — Top 3 things to focus on

Arvind Telharkar
Effective Java
Published in
4 min readDec 20, 2021

Java is a great language for coding interviews — provided you are well-equipped! Based on my experience, I feel it is critical to focus on these 3 things before you leap ahead —

Photo by JESHOOTS.COM on Unsplash

1. Standard Java built-ins vs Framework specifics

We are talking about Coding interviews here. What are coding interviews meant for anyway? — to see whether you can translate business logic correctly and fluently into code and produce the desired result! Hence, being solid with the basic structures and built-ins is the key. Framework specific deep knowledge of Spring or Hibernate etc. is great to have — maybe for some other conversational interview about Java, but that certainly does not help with the coding interview where you open a shared editor or step up to write code on a whiteboard!

You should have fluency in using the following standard Java classes & methods —

  • MapsHashMap, TreeMap, LinkedHashMap. You need to know the standard methods like get(), put(), containsKey() etc.
  • ListsArrayList is the most common. add(), size(), get() are the methods to know at minimum.
  • StringscharAt(), indexOf(), split(), length(), toString(), equals() are the ones you should know. StringBuilder’s append() is also an important method to know.
  • Arrays.length(this is not a method!), sort() are amongst the common things used.
  • Setsadd() and contains() for adding and checking membership in a Set respectively are quite useful to know.

If you don’t know these well, you should probably not say that Java is your strongest coding language!(It is a standard practice where companies ask for this before the coding interview is set up).

2. Toolbox of standard programming operations

Just knowing the standard classes and methods does not help. You also need to be able to quickly implement the standard programming operations to get the desired result. You should be able to do the following with ease —

  • Comparing or Sorting custom objects based on a given condition — This could involve use of Comparator interface or even Comparable, as some might prefer. For e.g. “Find Top K frequent words in a list” — You know Map classes like HashMap and TreeMap and can write loops fluently. But you don’t know how to compare 2 strings based on a custom condition & you can’t get the code working! — These are tiny loopholes related to the language choice(Java in this case), which can stop you from cracking interviews!
  • Clean custom classes — You will often have to quickly create custom classes from scratch to model certain things or behaviour. Make sure you can do so while following the best practices of class design — descriptive names & casing(yes! Naming shows how you write code in production everyday!), clean code, principle of single responsibility etc. If you give sloppy names, write shabby methods — it doesn’t give a good impression about your level of comfort with the language.
  • Iteration — You should be familiar with all standard loop types(for, foreach, while, do-while etc.). You should also be comfortable iterating over standard structures like a HashMap. Can you quickly iterate over all keys(only keys), or values(only values), or entries(key-value pairs) of a HashMap? If the answer is no — I think we have found a loophole in your preparation! Same applies to other standard structures like arrays, strings, lists etc.

3. Knowledge of data structures and algorithms

I am not going to rattle off too many names here. You need to know the following data structures at minimum —

  • LinkedLists
  • Binary Trees
  • Hash Tables(This is super important)!

For algorithms, basic ones like Binary Search, Breadth First Search(BFS), Depth First Search(DFS) should be enough. For most companies, you don’t need to go beyond this.

Last but not the least —being able to find the Time and Space complexity of your code is critical!

Bonus points to you if you can implement each of these data structures on your own! Can you implement a custom HashTable class in Java that implements put() and get() methods from scratch? If you are wondering whether this is a hypothetical, unrelated or imaginary question —I was tested on this during a phone screen by a top tech company in the Silicon Valley!

If you want to connect with me, feel free to reach out on LinkedIn!

To take your Java development skills to the next level, be sure to checkout and follow Effective Java!

--

--