I had a technical interview last week for a Java Software Engineer position. They asked some pretty basic questions such as:
1) What's the difference between an abstract class and an interface? Which do you use more?
2) How does garbage collection work in Java?
3) What is the difference between pass-by-value and pass-by-reference?
4) What is inheritance?
5) What is encapsulation?
Then the interviewer asked these questions which I wasn't too sure about:
6) What good coding practices do you follow?
7) What is the difference between an ArrayList, HashSet, and KeySet?
8) Which is better for garbage collection: allocation of 128 MB or 1 GB of memory?
9) What are some performance issues you've encountered with Java?
I feel like I did rather well on questions 1-5, but I feel like I struggled a little on questions 6-9. I answered 6-9 the following way:
6) Proper error/exception handling, limiting scope of variables, restricting access to variables and methods (encapsulation), promoting maintainability and readability (well commented code), using interfaces more than abstract classes when applicable (since implementing interfaces provides more flexibility).
7) ArrayList - Resizable data structure which allows you to store any data type of type Object. ArrayLists are not synchronized.
HashSet - Allows null elements. Constant time for add and remove operations.
KeySet - Is a set containing all the keys from a HashMap. (This confused me because I didn't consider a KeySet a data structure)
8) I wasn't too sure how to answer this question. When the interviewer asked me this question, I said 1 GB was better since garbage collection wouldn't occur as much. He disagreed with me and said that 128 MB was better because garbage collection wouldn't take as long. I responded by saying that it depends on the demands of the Java application and that allocating less space would more likely result in OutOfMemoryErrors. I then said there's a trade-off. He simply said, "Oh, okay"...Eek!
9) This question stumped me. I simply said that Java might be considered slower than some languages. I gave an example of how one of the projects at my current company tried converting C++ code to Java and how the performance was a lot slower compared to C++. Based on his reaction to my answer, he didn't seem too impressed. After my interview, I researched online about performance issues with Java, but didn't find anything useful.
So my question is, how did I do on questions 6-9? What did I miss in each of those questions? How would you have answered these questions?
I would really like to nail my next interview if these questions are asked again (whenever that is)!
Thanks in advance!