150+ Java Interview Questions for Experienced Developers - Part 1
150+ Java Interview Questions That Separate $100K from $200K Engineers
Preparing for System Design Interviews? Join ByteByteGo now for a structured preparation. They are also offering a rare 50% discount now on their lifetime plan
Hello guys, Time is changing and so is Java interviews. Gone are the days, when knowing the difference between String and StringBuffer can help you to go through the second round of interview, questions are becoming more advanced and interviewers are asking more deep questions.
When I started my career, questions like Vector vs Array and HashMap vs Hashtable were the most popular ones and just memorizing them gives you a good chance to do well in interviews, but not anymore.
Nowadays, you will get questions from the areas where not many Java programmer looks e.g. System Design, NIO, patterns, Stream API, sophisticated unit testing or those which are hard to master e.g. concurrency, algorithms, data structures and coding.
Since I like to explore interview questions, I have got this huge list of questions with me, which contains lots and lots of questions on different topics. I have been preparing this MEGA list for quite some time and now It’s ready to share with you guys.
It contains interview questions not only from classic topics like threads, collections, equals and hashcode, sockets but also from NIO, array, string, Stream API, Functional Programming, and much more.
📣Educative.io (Sponsored)
Educative.io is one of the most trusted platforms for learning system design, coding interviews, backend development, cloud, and AI engineering. It offers over 1,500 interactive courses, hands-on labs, real-world projects, and structured learning paths created by industry experts.
If you have been planning to upskill in system design, distributed systems, data engineering, or AI, this is a rare opportunity to get full access at a significantly reduced price.
The 50% discount offer is expiring soon, so if you always wanted to join Educative, don’t miss it.
It has questions for both entry-level Java programmers and senior developers with years of experience. No matter whether you are a Java developer of 1, 2, 3, 4, 5, 6, 8, 9, or even 10 years of experience, you will find something interesting in this list.
It contains questions that are super easy to answer, and also, a question that is tricky enough for even seasoned Java programmers. If you need more questions then you can also check out these Java Interview Courses and books to better prepare yourself.
Given the list is long and we have questions from everywhere, it’s imperative that answers must be short, concise, and crisp, with no fluffing at all.
So apart from this paragraph, you will only hear from me in the questions and answers, no more context, no more feedback, and no more evaluation.
For that, I have already written blog posts, where you can find my views on a particular question, e.g. why I like that question, what makes them challenging, and what kind of answer you should expect from candidates.
This list is a little bit different and I encourage you to share questions and answers in a similar way so that it should be easy to revise.
I hope this list can be of great use for both interviewer and candidates, the interviewer can, of course, but a little variety on questions to bring novelty and surprise element, which is important for a good interview.
While a candidate, can expand and test their knowledge about key areas of Java programming language and platform.
Nowadays and in coming years the focus will be more on advanced concurrency concepts, JVM internals, 32-bit vs 64-bit JVM, unit testing, and clean code. I am sure, once you read through this MEGA list of Java interview questions, you should be able to do well on both telephonic and face-to-face programming interviews.
I have also written a book for Java interviews, Grokking the Java Interview, and Grokking the Spring Boot Interview, where I have shared tips, tricks and frequently asked Java questions from different topics.
If you are keen to do well and better prepare for Java interviews, you can also take a look at that. If you want to buy, use the code — friends20 to get a 20% discount because you are already my reader.
22 Essential Topics for Java Developer Interviews
Apart from quantity, as you can see with a huge number of questions, I have worked hard to maintain quality as well.
I have not only shared questions from all important topics but also ensured to include so-called advanced topics which many programmers do not prefer to prepare or just left out because they have not worked on that.
Java NIO and JVM internals questions are the best examples of that. You can keep design patterns also on the same list but a growing number of experienced programmers are now well aware of GOF design patterns and when to use them.
I have also worked hard to keep this list up-to-date to include what interviewers are asking nowadays and what will be their core focus in the coming years. To give you an idea, this list of Java interview questions includes the following topics:
Multithreading, concurrency, and thread basics
Date type conversion and fundamentals
Garbage Collection
Java Collections Framework
Array
String
GOF Design Patterns
SOLID design principles
Abstract class and interface
Java basics like equals() and hashcode
Common Networking protocols
Data structure and algorithm in Java
Regular expressions
JVM internals
Java Best Practices
JDBC
Date, Time, and Calendar
XML Processing in Java
JUnit
Programming
You guys are also lucky that nowadays there are some good books available to prepare for Java interviews, one of them which I particularly find useful and interesting to read is Java Programming Interview Exposed by Markham. It will take you to some of the most important topics for Java and JEE interviews, worth reading even if you are not preparing for a Java interview.
150 Java Interview Questions Answers for 1 to 5 Years Experienced Programmers
So now the time has come to introduce you to this MEGA list of 120 Java questions collected from various interviews of last 5 years. I am sure you have seen many of these questions personally on your interviews and many of you would have answered them correctly as well.
1. Multithreading, Concurrency and Thread basics Questions
Let’s start with the toughest topic on Java interviews, multithreading and concurrency, once you master this topic, you are already ahead of many Java developers who don’t understand threads in depth.
1) Can we make array volatile in Java?
This is one of the tricky Java multi-threading questions you will see in senior Java developer Interview. Yes, you can make an array volatile in Java but only the reference which is pointing to an array, not the whole array.
What I mean, if one thread changes the reference variable to points to another array, that will provide a volatile guarantee, but if multiple threads are changing individual array elements they won’t be having happens before guarantee provided by the volatile modifier.
2) Can volatile make a non-atomic operation to atomic?
This another good question I love to ask on volatile, mostly as a follow-up of the previous question. This question is also not easy to answer because volatile is not about atomicity, but there are cases where you can use a volatile variable to make the operation atomic.
One example I have seen is having a long field in your class. If you know that a long field is accessed by more than one thread e.g. a counter, a price field or anything, you better make it volatile.
Why? because reading to a long variable is not atomic in Java and done in two steps.
If one thread is writing or updating long value, it’s possible for another thread to see half value (fist 32-bit). While reading/writing a volatile long or double (64 bit) is atomic.
3) What are practical uses of volatile modifier?
One of the practical use of the volatile variable is to make reading double and long atomic. Both double and long are 64-bit wide and they are read in two parts, first 32-bit first time and next 32-bit second time, which is non-atomic but volatile double and long read is atomic in Java.
Another use of the volatile variable is to provide a memory barrier, just like it is used in Disruptor framework. Basically, Java Memory model inserts a write barrier after you write to a volatile variable and a read barrier before you read it.
Which means, if you write to volatile field then it’s guaranteed that any thread accessing that variable will see the value you wrote and anything you did before doing that right into the thread is guaranteed to have happened and any updated data values will also be visible to all threads, because the memory barrier flushed all other writes to the cache.
4) What guarantee volatile variable provides? (answer)
volatile variables provide the guarantee about ordering and visibility e.g. volatile assignment cannot be re-ordered with other statements but in the absence of any synchronization instruction compiler, JVM or JIT are free to reorder statements for better performance.
The volatile modifier also provides the happens-before guarantee which ensures changes made in one thread is visible to others.
In some cases volatile also provide atomicity e.g. reading 64-bit data types like long and double are not atomic but read of volatile double or long is atomic.
5) Which one would be easy to write? synchronization code for 10 threads or 2 threads?
In terms of writing code, both will be of same complexity because synchronization code is independent of a number of threads.
Choice of synchronization though depends upon a number of threads because the number of thread present more contention, so you go for advanced synchronization technique e.g. lock stripping, which requires more complex code and expertise.
6) How do you call wait() method? using if block or loop? Why? (answer)
The wait() method should always be called in loop because it’s possible that until thread gets CPU to start running again the condition might not hold, so it’s always better to check condition in loop before proceeding.
Here is the standard idiom of using wait and notify method in Java:
// The standard idiom for using the wait method
synchronized (obj) {
while (condition does not hold)
obj.wait(); // (Releases lock, and reacquires on wakeup)
... // Perform action appropriate to condition
}See Effective Java Item 69 to learn more about why wait method should call in the loop.
7) What is false sharing in the context of multi-threading?
false sharing is one of the well-known performance issues on multi-core systems, where each process has its local cache. false sharing occurs when threads on different processor modify variables that reside on same cache line as shown in the following image:
False sharing is very hard to detect because the thread may be accessing completely different global variables that happen to be relatively close together in memory.
Like many concurrency issues, the primary way to avoid false sharing is careful code review and aligning your data structure with the size of a cache line.
This question is quite popular on low latency Java developer interviews on Investment banks, hedge funds, HFT companies and Crypto exchanges.
8) What is busy spin? Why should you use it?
Busy spin is one of the technique to wait for events without releasing CPU. It’s often done to avoid losing data in CPU cached which is lost if the thread is paused and resumed in some other core.
So, if you are working on low latency system where your order processing thread currently doesn’t have any order, instead of sleeping or calling wait(), you can just loop and then again check the queue for new messages.
It’s only beneficial if you need to wait for a very small amount of time e.g. in microseconds or nanoseconds. LMAX Disrupter framework, a high-performance inter-thread messaging library has a BusySpinWaitStrategy which is based on this concept and uses a busy spin loop for EventProcessors waiting on the barrier.
9) How do you take thread dump in Java?
You can take a thread dump of Java application in Linux by using kill -3 PID, where PID is the process id of Java process. In Windows, you can press Ctrl + Break.
This will instruct JVM to print thread dump in standard out or err and it could go to console or log file depending upon your application configuration. If you have used Tomcat then when
10) is Swing thread-safe? (answer)
No, Swing is not thread-safe. You cannot update Swing components e.g. JTable, JList or JPanel from any thread, in fact, they must be updated from GUI or AWT thread.
That’s why swings provide invokeAndWait() and invokeLater() method to request GUI update from any other threads.
This methods put update request in AWT threads queue and can wait till update or return immediately for an asynchronous update. You can also check the detailed answer to learn more.
11) What is a thread local variable in Java? (answer)
Thread-local variables are variables confined to a thread, its like thread’s own copy which is not shared between multiple threads. Java provides a ThreadLocal class to support thread-local variables. It’s one of the many ways to achieve thread-safety.
Though be careful while using thread local variable in managed environment e.g. with web servers where worker thread out lives any application variable.
Any thread local variable which is not removed once its work is done can potentially cause a memory leak in Java application.
12) Write wait-notify code for producer-consumer problem? (answer)
Please see the answer for a code example. Just remember to call wait() and notify() method from synchronized block and test waiting for condition on the loop instead of if block.
13) Write code for thread-safe Singleton in Java?
Please see the answer for a code example and step by step guide to creating thread-safe singleton class in Java. When we say thread-safe, which means Singleton should remain singleton even if initialization occurs in the case of multiple threads. Using Java enum as Singleton class is one of the easiest ways to create a thread-safe singleton in Java.
14) The difference between sleep and wait in Java?
Though both are used to pause currently running thread, sleep() is actually meant for short pause because it doesn’t release lock, while wait() is meant for conditional wait and that’s why it release lock which can then be acquired by another thread to change the condition on which it is waiting.
15) What is an immutable object? How do you create an Immutable object in Java?
Immutable objects are those whose state cannot be changed once created. Any modification will result in a new object e.g. String, Integer, and other wrapper class. Please see the answer for step by step guide to creating Immutable class in Java.
16) Can we create an Immutable object, which contains a mutable object?
Yes, its possible to create an Immutable object which may contain a mutable object, you just need to be a little bit careful not to share the reference of the mutable component, instead, you should return a copy of it if you have to. Most common example is an Object which contain the reference of java.util.Date object.
That’s all about the core Java interview questions in this part guys. I will share more question on second part where we will see the Date type conversion and fundamentals, so stay tuned for next part. You can also share this post to your friends who are preparing for Java interviews, its free.
In case you don’t know, I have also written a book for Java interviews, Grokking the Java Interview, and Grokking the Spring Boot Interview, where I have shared tips, tricks and frequently asked Java questions from different topics.
You can read the book to better prepare for your Java interviews. You can also use the code — friends20 to get a 20% discount because you are already my reader.
Other Java and Spring Boot Interview Questions you may like








Solid breakdown here. The shift from memorizing Vector vs Array to understanding concurrency patterns and system design really separates experienced devs. I remember prepping for a senior role last year and the focus was all aboout wait/notify idioms and false sharing. Btw that call-out on using volatile for atomicity with 64-bit types is underrated knowledge. Most folks miss that nuance.