0% found this document useful (0 votes)
15 views

Interview Process For Java Developers

The document discusses the process for interviewing Java developer candidates. It covers reviewing a candidate's background, assessing Java language knowledge, framework experience, data structure and algorithm skills, and ability to design solutions. It includes sample questions in several appendices related to these areas to help evaluate candidates.

Uploaded by

kobezeq
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Interview Process For Java Developers

The document discusses the process for interviewing Java developer candidates. It covers reviewing a candidate's background, assessing Java language knowledge, framework experience, data structure and algorithm skills, and ability to design solutions. It includes sample questions in several appendices related to these areas to help evaluate candidates.

Uploaded by

kobezeq
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Table of Contents

Table of Contents

1 INTERVIEW PROCESS...............................................................................................................2
1.1 Technical Interview – Structure..............................................................................................2
1.1.1 Review the Professional Background of the Candidate.......................................................2
1.1.2 Warm Up.............................................................................................................................2
1.1.3 Java Language Knowledge...................................................................................................3
1.1.4 Java Framework Knowledge................................................................................................3
1.1.5 Data Structure and Logic Questions....................................................................................3
1.1.6 Design.................................................................................................................................4
APPENDIX A – BASIC JAVA QUESTIONS..............................................................................................5
APPENDIX B – BASIC JAVA FRAMEWORK QUESTIONS........................................................................7
Hibernate..............................................................................................................................................7
Spring 7
APPENDIX C – DATA STRUCTURES, LOGIC & ALGORITHMS...............................................................10
Immutable..........................................................................................................................................10
Reverse a Stack...................................................................................................................................11
Throttling Problem..............................................................................................................................12
Cache Problem....................................................................................................................................12
APPENDIX D – SIMPLE DESIGN QUESTIONS......................................................................................14
Chess Game........................................................................................................................................14

Page
Java Developer – Interview Process

1 Interview Process

This section focuses on the technical part of the interview. The interviewer must review the
candidate’s CV before the interview and understand the reasons for searching for a new position.

At any point if you are sure that the candidate does not fit then there is no point in continue the
interview.

1.1 Technical Interview – Structure

1.1.1 Review the Professional Background of the Candidate

i. Objective:
- Understand what was the candidate role and responsibilities
- What the candidate did by himself and to what exactly the candidate was responsible
- How well the candidate is familiar with the product, implementation and overall
architecture

ii. How to:


- Explain main modules and their interfaces
- Explain main flows
- Explain design considerations
- Point the complicated area and what was done to overcome the challenges
- How his module can be extended, adopt changes in requirements
- Discuss async flow in the system
- Where state is kept
- Error scenarios and Recoverability
- Discuss concurrency and the performance of the system
- Challenge the design and see how the candidate will react

iii. Expectations:
- Clearly explain the system and its main modules
- Clearly explain what the product/system does
- Organized
- Knows the details and familiar with design decisions (if not a junior)
- Can describe what the candidate would have done differently and why

1.1.2 Warm Up

i. Objective:
- Free style questions what meant to understand how the candidate react to stuff the
candidate is not familiar

Java interview for developers Page 2


Java Developer – Interview Process

- See how the candidate thinks and approach to such problems


- See how the candidate can listen to hints and use them to progress to the solution

1.1.3 Java Language Knowledge

i. Objective:
- Verify the candidate has a good knowledge in the Java language and the way Java
program is running

ii. How to:


- Using a few questions from Appendix A – java basic questions

iii. Expectations
- Correct answer to most questions

1.1.4 Java Framework Knowledge

i. Objective:
- Verify the candidate has a good knowledge in common Java framework, how they
are used and why, benefit from using them etc. Usually candidates declare that they
are familiar with in their CV.

ii. How to:


- Understand first which framework the candidate knows, from where did the
candidate gain his experience
- Ask the candidate to describe what the framework provides, how it does that
- Which capabilities from the framework the candidate knows and used
- Using a few questions from Appendix B – java framework questions

iii. Expectations
- Good understanding of framework the candidate used
- Good candidates know how the framework is implemented and what are the
advanced features
- Average candidates knows only basic features and have difficulties to explain and
describe the benefit, design etc

1.1.5 Data Structure and Logic Questions

i. Objective:
- See that the candidate can think of effect solutions to data structure related problems
- Basic algorithm understanding
- Knows how to evaluate the complexity of the solution the candidate provided
- Understand hints and use them for improving a non-efficient algorithm

ii. How to:

Java interview for developers Page 3


Java Developer – Interview Process

- The questions in this section should be structure in a way that is fairly simple to find
a non-efficient solution and then it gets complex to reach the effect one. The
candidate will likely need assistance to reach the best solution.
- Using a few questions from Appendix C – Data structure & Algorithm questions

iii. Expectations
- Exceptional candidates reach the best solution without help
- Good ones find the simple solution quickly and then with some assistance reach the
desired solution
- Below average either can’t pass the simple solution

1.1.6 Design

i. Objective:
- Check the candidate ability to do a quick design to a problem
- Good separation to classed
- Good isolation of logic to component
- Reuse when possible
- Main flows are easily described using the created classes and their APIs

ii. How to:


- Using a few questions from Appendix D – java design questions

iii. Expectations
- Good design with clear separation to classes and clear isolation and boundaries
- Easily adopt to changes
- Efficient

Java interview for developers Page 4


Java Developer – Interview Process

Appendix A – Basic Java Questions

1. What is the difference between an Interface and an Abstract class?


An abstract class can have instance methods that implement a default behavior. An Interface
can only declare constants and instance methods, but cannot implement default behavior and
all methods are implicitly abstract. An interface has all public members and no implementation.
An abstract class is a class which may have the usual flavors of class members (private,
protected, etc.), but has some abstract methods.

2. What is an abstract class?


Abstract class must be extended/subclassed (to be useful). It serves as a template. A class that is
abstract may not be instantiated (ie. you may not call its constructor), abstract class may contain
static data. Any class with an abstract method is automatically abstract itself, and must be
declared as such. A class may be declared abstract even if it has no abstract methods. This
prevents it from being instantiated

3. Describe synchronization in respect to multithreading.


With respect to multithreading, synchronization is the capability to control the access of multiple
threads to shared resources. Without synchonization, it is possible for one thread to modify a
shared variable while another thread is in the process of using or updating same shared variable.
This usually leads to significant errors.

4. What are Checked and UnChecked Exception?


A checked exception is some subclass of Exception (or Exception itself), excluding class
RuntimeException and its subclasses. Making an exception checked forces client programmers to
deal with the possibility that the exception will be thrown. Example: IOException thrown by
java.io.FileInputStream's read() method•

Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its
subclasses also are unchecked. With an unchecked exception, however, the compiler doesn't
force client programmers either to catch the exception or declare it in a throws clause. In fact,
client programmers may not even know that the exception could be thrown. Example:
StringIndexOutOfBoundsException thrown by String's charAt() method• Checked exceptions
must be caught at compile time. Runtime exceptions do not need to be. Errors often cannot be.

5. What is the purpose of garbage collection in Java, and when is it used?


The purpose of garbage collection is to identify and discard objects that are no longer needed by
a program so that their resources can be reclaimed and reused. A Java object is subject to
garbage collection when it becomes unreachable to the program in which it is used.

6. What are the differences between JDK and JRE?


o JRE: Java Runtime Environment. It is basically the Java Virtual Machine where your Java
programs run on. It also includes browser plugins for Applet execution.
o JDK: It's the full featured Software Development Kit for Java, including JRE, and the
compilers and tools (like JavaDoc, and Java Debugger) to create and compile programs.

Java interview for developers Page 5


Java Developer – Interview Process

Usually, when you only care about running Java programs on your browser or computer you will
only install JRE. It's all you need. On the other hand, if you are planning to do some Java
programming, you will also need JDK.

Sometimes, even though you are not planning to do any Java Development on a computer, you
still need the JDK installed. For example, if you are deploying a WebApp with JSP, you are
technically justrunning Java Programs inside the application server. Why would you need JDK
then? Because application server will convert JSP into Servlets and use JDK to compile the
servlets. I am sure there might be more examples.

7. What is a class loader?


ClassLoaders are used in large systems and server applications to do things like:

Modularize a system and load, unload and update modules at runtime

Use different versions of an API library (e.g. an XML parser) in parallel

Isolate different applications running within the same JVM (ensuring they don't interfere with
each other, e.g. through static variables)

8. How memory leaks happen in Java?


Static field holding object reference, (Unclosed) open streams (file , network etc... ), Unclosed DB
connections

Java interview for developers Page 6


Java Developer – Interview Process

Appendix B – Basic Java Framework Questions

Hibernate

1. What is OR Mapping?
Object-relational mapping (ORM) is a mechanism that makes it possible to address, access and
manipulate objects without having to consider how those objects relate to their data sources.
ORM lets programmers maintain a consistent view of objects over time, even as the sources that
deliver them, the sinks that receive them and the applications that access them change.

Based on abstraction, ORM manages the mapping details between a set of objects and
underlying relational databases, XML repositories or other data sources and sinks, while
simultaneously hiding the often changing details of related interfaces from developers and the
code they create.

2. What is HQL?
Hibernate Query Language (HQL) is an object-oriented query language, similar to SQL, but
instead of operating on tables and columns, HQL works with persistent objects and their
properties. HQL queries are translated by Hibernate into conventional SQL queries which in
turns perform action on database.

Although you can use SQL statements directly with Hibernate using Native SQL but I would
recommend to use HQL whenever possible to avoid database portability hassles, and to take
advantage of Hibernate's SQL generation and caching strategies

3. What are 1st and 2nd level cache?


First-level cache always Associates with the Session object. Hibernate uses this cache by default.
Here, it processes one transaction after another one, means wont process one transaction many
times. Mainly it reduces the number of SQL queries it needs to generate within a given
transaction. That is instead of updating after every modification done in the transaction, it
updates the transaction only at the end of the transaction.

Second-level cache always associates with the Session Factory object. While running the
transactions, in between it loads the objects at the Session Factory level, so that those objects
will be available to the entire application, not bound to single user. Since the objects are already
loaded in the cache, whenever an object is returned by the query, at that time no need to go for
a database transaction. In this way the second level cache works. Here we can use query level
cache also. Later we will discuss about it.

Spring

1. Describe Dependency Injection


Java components / classes should be as independent as possible of other Java classes. This
increases the possibility to reuse these classes and to test them independently of other
classes(Unit Testing). To decouple Java components from other Java components the

Java interview for developers Page 7


Java Developer – Interview Process

dependency to a certain other class should get injected into them rather that the class itself
creates / finds this object.

A class A has a dependency to class B if class uses class B as a variable.

If dependency injection is used then the class B is given to class A via

o the constructor of the class A - this is then called construction injection

o a setter - this is then called setter injection

The general concept between dependency injections is called Inversion of Control. A class should
not configure itself but should be configured from outside.

A design based on independent classes / components increases the re-usability and possibility to
test the software. For example, if a class A expects a Dao (Data Access object) for receiving the
data from a database you can easily create another test object which mocks the database
connection and inject this object into A to test A without having an actual database connection.

Spring just simplifies the use of dependency injection by providing a standard way of providing
the configuration and by managing the reference to the created objects.

2. Describe Interceptors
Interceptors are components that intercept calls to classes and methods. They can be used for
adding logging, auditing, and security capabilities without coupling to the business logic.

Interceptor can add pre invocation and post invocation logic.

3. Describe Controller in Spring-MVC


4. Describe Spring JDBC
XML

5. Differences between DOM and SAX based parsers


In SAX, events are triggered when the XML is being parsed. When the parser is parsing the XML,
and encounters a tag starting (e.g. <something>), then it triggers the tagStarted event (actual
name of event might differ). Similarly when the end of the tag is met while parsing
(</something>), it triggers tagEnded. Using a SAX parser implies you need to handle these events
and make sense of the data returned with each event.

In DOM, there are no events triggered while parsing. The entire XML is parsed and a DOM tree
(of the nodes in the XML) is generated and returned. Once parsed, the user can navigate the tree
to access the various data previously embedded in the various nodes in the XML.

Differences:

a. DOM parser loads whole xml document in memory while SAX only loads small part of XML
file in memory.
b. DOM parser is faster than SAX because it access whole XML document in memory.

Java interview for developers Page 8


Java Developer – Interview Process

c. SAX parser in Java is better suitable for large XML file than DOM Parser because it doesn't
require much memory.
d. DOM parser works on Document Object Model while SAX is an event based xml parser.

Java interview for developers Page 9


Java Developer – Interview Process

Appendix C – Data Structures, Logic & Algorithms

Immutable

What is Immutable?

An object is considered immutable if its state cannot change after it is constructed

Create Immutable class “Person”

Class should have following members:

o Name – String

o Address – String

o Birth date – Date

public final class Person {

private final String name;


private final String address;
private final Date birthDate;

public Person(String name, String address, Date birthDate) {


this.name = name;
this.address = address;
this.birthDate = new Date(birthDate.getTime());
}

public String getName(){


return name;
}

public String getAdress(){


return address;
}

public Date getBirthDate(){


return (Date) birthDate.clone();
}

Java interview for developers Page 10


Java Developer – Interview Process

Reverse a Stack

The problem

Stack is defined by object with pop, push and size functions. Write a function that reverses the
order of the elements in the stack. The function signature is: public void reverse(Stack s)

You can use only other stacks and native/simple temporary variables. The solution can be
explained in words, there is no need to write the full code.

Step 1 - Trivial solution (most people provide it):

a. Use 2 temporary stacks – t1, t2


b. Move (pop and push) from s to t1
c. Move (pop and push) from t1 to t2
d. Move (pop and push) from t2 to s
Step 2 – Additional implementation limitation:

Provide a solution to the same problem using only 1 temporary stack.

solution 1 – inefficient (most people that answer this part, provide this solution)

Iterate over the stack elements as follows:

a. Pop from s to a temporary variable


b. Move (pop and push) all the rest from s to t1 (i.e. in the first iteration move n-1 elements, in
the second iteration move n-2 elements, and so on)
c. Push the popped element back to s
d. Move (pop and push) all the rest from t1 back to s
e. Repeat for all stack elements
This solution is O(n!)

Step 3 – Additional limitation – efficiency:

Ask if a more efficient solution can be found to run in O(n).

Solution:

a. Use recursion to copy s to t1 as follows:


i. Pop from s to a temporary variable
ii. Call the recusive copy
iii. Push the temporary variable to t1
The idea is to use the call stack as an additional temporary stack.

Java interview for developers Page 11


Java Developer – Interview Process

Each recursive call saves the popped item on the call frame.

When the frames fold back, push the variable to the temporary stack.

b. Move (pop and push) from t1 back to s

Throttling Problem

Server A is deployed with our system that receives transactions which goes through some processing
steps.

In one of the steps a notification request is generated and sent to a 3rd party server.

After a few days from the system deployment, we got a call from the 3rd party system vendor saying
that we keep crashing their server.

After some investigation, it turned out that the vendor’s server supports up to 1000 transactions per
minute while our system supports up to 10000 transactions per minute.

How do you suggest to solve this problem?

Solution approach:

The requests should be queued and a time based event should wake up every X seconds and
pick up 1000*X/60 requests from the Q and send it to the 3rd party server.

Cache Problem

Suppose you were asked to implement a naïve cache with a simple API – put (K, V), get (K).

The cache is limited in number of entries, once it reached its maximum capacity eviction based on
LRU (least recently used, discards the least recently used items firsts) should be triggered. Suggest an
efficient data structure to support that.

Note that both put and get are accessing the element in the cache therefore refresh the item in the
LRU (e.g. get(k) means that the item is used therefore it become the last in the list of candidates to
be discarded due to LRU eviction).

Solution:

We will use two data structures that maintain the same objects. The data types are Map and Double
Linked list. This solution will provide O(1) complexity for both get and put operations.

The element in the map and in the list will wrap the received V and will include two references
next, prev in order to maintain a double linked list. Assume that the first element in the list is the
least recently used. You will maintain the head and the tail separately.

Java interview for developers Page 12


Java Developer – Interview Process

Put(K, V) api – Create an element that will wrap the V and add it to the Map using the K key. The
element will be added as the last item in the list as well so the element.prev = tail and tail.next =
element and tail = element.

Get(K) api – Get the element from the map using the K key. Now we need to update the list and
move the element to be the last one. Since we have direct access to it once we fetched it from the
Map (no need to scan the list and lookup this element!!) it simply means to update the relevant
next, prev and tail references. The get api will return the element.V.

When the cache reached its maximum capacity to simply need to remove the element from the
head of the list and using the element.K remove it also from the Map

Java interview for developers Page 13


Java Developer – Interview Process

Appendix D – Simple design questions

Chess Game

Ask the user to do a design for chess game where 2 players can play a chess game. Ask the candidate
to think about the main classes and objects, define the APIs and describe a game flow using the
classes the candidate designed. The candidate should be able to explain the following:

1. How to create a new game


2. The sequence that happen once a player perform a move
3. When and how chess is checked
4. When and how checkmate is declared
5. How to verify that a move is valid and that the player played in his turn

Expect to see at least the following classes – player, board, game manager, piece interface, piece
implementation – king, queen etc

Verify how chess is checked – should be checked at the end of each move, note that chess can
happen even by pieces that didn’t move but after the last move have a way to reach the opponent’s
king.

Verify how checkmate is checked

Verify that the candidate doesn’t scan the entire board each time there is a need to look up for the
opponent’s king. The candidate should maintain a direct references to the white & black kings.

If the design was good, you can ask the candidate to add a chess clock for the design and see what
are his suggestions

Java interview for developers Page 14

You might also like