18 October 2015

Java Interview Questions

Java Interview Questions

In the past, I was a Software Developer, and my primary programming language was Java. I also quite often interviewed people and also sometimes was an interviewee. In this post, I would like to share typical questions that you might expect at a job interview for a Java Developer position.

Let’s get started!

Table of Content



  • What programming languages do you know and use?
  • What is your most hated technology or tool and why?
  • Which technology do you consider yourself expert in?
  • What was the biggest challenge you encountered? How did you deal with it?
  • Tell me about your biggest professional achievement
  • What was the last book you’ve read? What was the most important point you remembered from the book?


Algorithms & Data structures

  • Which data structures do you know? Tell me about one of them
  • What is recursion? tail recursion, mutual recursion?
  • Complexity of algorithms, big notation
  • Which sorting algorithms do you know?
  • How to sort a linked list?
  • Linear-time sorting (count sort)?
  • Trees, graphs and ways to traverse graph
  • What is a binary tree?
  • How to search in binary tree?
  • Self balanced trees (Red-black tree, AVL, Splay)
  • Tries, prefix and suffix trees
  • What is NP-completeness? What algorithms are NP-Complete?
  • What is the divide and conquer approach?
  • Tell me about Dynamic programming
  • What is MapReduce?


Java Core


  • What access modifiers do you know in Java?
  • What is the contract between equals() and hashCode()?
  • Rules to implement the equals method (stability, transitivity, reflectivity etc)?
  • Why do we need nested classes?
  • What is immutability? Why is it good?
  • How to make a class immutable?
  • Besides String do you know any other immutable classes from JDK?
  • Can a interface inherit from another interface?
  • What is the difference between regular vs. static initialization blocks?



  • How exceptions are handled in Java?
  • Java Exceptions API. What standard exceptions do you know?
  • Checked vs unchecked exceptions. When would you use them?
  • Is there any difference between handing Error and Exception?
  • Can we have only try and finally without catch? If yes, when is it useful?
  • What is try-with-resource?
  • Is it possible that the finally block is not executed? When?



  • Collection API. Can you list general collection API? (e.g. Collection, Set, Map, List, Queue, SortedSet, SortedMap, etc)
  • Can you say how these interfaces are related?
  • Does Map extend the Collection interface?
  • What is the difference between ArrayList and LinkedList?
  • What is the difference between Stack and Queue?
  • TreeSet vs LinkedHashSet
  • How HashMap is implemented? How collisions are resolved there?
  • How to implement hashCode to achieve the best performance?
  • What is the difference between Hashtable and ConcurrentHashMap?
  • Do you know how ConcurrentHashMap is implemented? How is it different from usual HashMap or Hashtable?
  • Special implementations. Why do we need EnumSet, EnumMap? What about WeakHaskMap or IdentityHashMap?
  • What is ConcurentModificationException? How can we get it? How to avoid getting it?
  • Collections with safe iterators (CopyOnWriteArrayList/CopyOnWriteArraySet)



  • What is a parameterized or generic type?
  • Can we use parameterized types in exception handling?
  • What is a wildcard parameterized type?
  • What is autoboxing and what are its advantages/pitfalls?
  • Can we add something to List<?>?



  • How to make multithreaded code?
  • What’s the difference between extending Thread vs implementing Runnable?
  • What is the difference between Thread’s methods run() and start()?
  • Synchronization of java blocks and methods
  • How to use wait and notify?
  • What is the difference between Thread.sleep and wait?
  • What is an atomic operation? Is i++ atomic?
  • What does the volatile keyword mean?
  • Have you used java.util.concurrent.*? What have you used from there?
  • Why do we need ThreadLocal?
  • What is a deadlock? Can you give an example? How to cause it?
  • What is a livelock?
  • What is starvation?
  • What is the race condition?
  • Atomicity of long and double assignment operations
  • Lock-free operations. How to create lock-free implementation of field reassignment?
  • How to interrupt a thread?


Java IO and NIO

  • Can you describe the standard Java IO API?
  • What is the difference between InputStream and Reader? OutputStream and Writer?
  • How does BufferedReader work?
  • What is NIO?
  • What is Channel? What is Buffer?
  • How to lock a file?
  • What is NIO2?


Memory and Garbage Collector

  • Memory model in JVM
  • How does virtual space divided in Java? What is permgen? Is it still there in Java 8?
  • What difference between float and BigDecimal? How they store the data?
  • What is deep copy of a Java object?
  • What are the disadvantages of setting heap size too high?
  • What are utilities for JVM monitoring? What is Jconsole?
  • How to force GC be executed?
  • Garbage collection principles
  • What is a memory leak? How and why it can be caused?
  • What is variable shadowing?
  • How would you monitor JVM?
  • How would you monitor how GC behaves during program execution?
  • Name few GC implementations (Serial, Parallel, ParallelOld, ConcarentMarkAndSweep, G1) and describe major differences


Unit testing

  • What is unit testing?
  • Libraries that help to writing unit tests
  • Why do we need JUnit?
  • What is a mock? Have you used EasyMock or Mockito?


Database Questions

Database Engines

  • Does every DBMS system implement SQL in the same way?
  • What’s the difference between a table and a view?
  • What is a transaction? What is ACID?
  • Which transaction isolation levels do you know?
  • What is the difference between primary and secondary keys?
  • What types of constraints do you know?
  • What is a materialized view? How is it different from usual view?
  • What kind of joins do you know?
  • What is the difference between inner join and outer join?
  • Why do we need indexes?
  • Is it a good idea to have many different indexes? Why or why not?
  • What is a bitmap index?
  • How SELECT, UPDATE and DELETE statements are affected by indexes?
  • What is de-normalization and why would we do it?
  • How can we improve database performance?
  • Partitioning and methods of partitioning



  • Aggregate functions with examples
  • Given a schema, write some SQL query with group by / outer join / etc.
  • What is a nested subquery?



  • Did you need to process XML? How and why?
  • What is XPath? Have you used it?
  • Experience with XSLT
  • SAX vs DOM
  • DTD vs XMLSchema
  • What is the difference between HTML and XML?
  • What is well formed HTML?
  • What is XML namespace? Why is it useful?
  • What characters are disallowed from XML without escaping?



You are very likely to have questions about Spring, Hibernate, or any other frameworks used by the company.


  • What is Inversion of Control? Benefits?
  • What is Spring configuration file? How does it look like?
  • Out of the box bean scopes (singleton, prototype; request, session, global session)
  • Autowiring. Types of autowiring.
  • What modules does Spring Framework have?
  • Describe AOP integration in Spring


Software Design

Design patterns

  • What design patterns are in JDK? Can you give some examples? What about Java IO API?
  • Which patterns do you use on a daily basis? Explain their principles.
  • What is Façade/Proxy/Decorator/Strategy/Observer/etc? (selectively)



  • Inheritance vs Composition. Which is better? Why?
  • What is Coupling and Cohesion?
  • What is SOLID? Do you know what each letter stands for?
  • What is Single Responsibility Principle? Interface segregation principle? Dependency inversion principle?
  • Can you tell me about the DRY principle?
  • What is the Law of Demeter?
  • What is Feature Envy?
  • Do you know about CQRS (Command Query Responsibility Segregation)?
  • Principle of Least Astonishment/Surprise


The end

The main source of the questions is job interviews we conducted at Luxoft a few years ago while I was working as a Java Developer. This of course is by no means a full list, but I hope it can still be useful for your interview preparation.

If you’re also interested in Data Science job interview questions, then go here.

And finally, stay tuned for our new blog posts!

No comments:

Post a Comment