Core Java Interview Questions: Ultimate Collection

core Java interview questions
I had more than 50 interviews since 2010th.

I collected all the most interesting and useful Java interview questions.

This is not only basic coding interview questions or questions for experienced developers.

I think this collection would be good for everyone even if you’re basic (entry level) or advanced engineer (advanced level) or even architect.

I’m going to add answers step-by-step because It’s a really huge job.

If you have amazing Java programming interview questions that are not on my list – please, leave a comment with your question and I’ll update a list.

I’ve created a simple filter for you to filter basic (junior developers), middle (middle developers)  and advanced (senior developers) questions.During interview preparation, you should keep in mind that middle developer should know all basic and middle-level questions, senior should know basic, middle and advanced interview questions.

Of course, the interviewer could ask junior developer an advanced question and he will be really impressed if you’ll can give him a good answer.

Object-Oriented Programming (OOPs)

  1. What is OOP?
  2. What are main concepts of OOP?
  3. What is an encapsulation?
  4. What is a polymorphism?
  5. What is an inheritance?
  6. What is an abstraction and what are abstraction layers?
  7. Is-a and has-a relationships: what is it and how to use it?
  8. What do you prefer inheritance or composition?

JVM

  1. What is JVM?
  2. What is .jar?
  3. What is .war?
  4. What is a difference between .jar and .war?
  5. What is a difference between JRE, JVM, and JDK?
  6. What JIT compiler?

Classes

  1. What is a superclass of all classes?
  2. What access modifiers do you know?
  3. What is a difference between protected and package-private access modifiers?
  4. What is a difference between method and static method?
  5. What is a difference between final, finally and finalize?
  6. Can we declare static class? What is a difference with a non-static?
  7. What is an inner class?
  8. What is an anonymous class?
  9. What are wrapper classes? Is it mutable?
  10. What is class loader?
  11. What class loaders do you know?
  12. How does class loaders work?
  13. What does final keyword mean on the class and method level?
  14. What are method overriding rules?
  15. How can I access private fields?
  16. What is a reflection?
  17. What types of annotation retention do you know?

Objects

  1. What methods of Object class do you know?
  2. What is equals() and hashCode() and why do we need it?
  3. We’re comparing 2 objects, equals() method return true, hashCode() returns different numbers. Is it possible?
  4. We’re comparing 2 objects, equals() method return false, hashCode() returns the same numbers. Is it possible?
  5. How to serialize and deserialize object?
  6. How to clone an object?
  7. What is a difference between shallow copy and deep copy?
  8. What is an immutable object? What are benefits?
  9. How to make an object immutable?
  10. What are boxing and unboxing?
  11. Does Java pass by reference or pass by value?
  12. What is a difference between Comparable and Comparator?

Strings

  1. What is String Pool?
  2. What is a difference between substring() implementations in Java 6 and 7?
  3. How to configure String Pool size?
  4. Is String immutable? Why do you think is it a good idea?
  5. What is a difference between new String("") vs “”?
  6. What is a difference between String, StringBuilder and StringBuffer?

Numbers

  1. Is +0.0 и -0.0 possible? Why?
  2. Why  Integer.valueOf(127) == Integer.valueOf(127) is true, but  Integer.valueOf(128) == Integer.valueOf(128) is false?
  3. What is BigDecimal?

Abstract Classes and Interfaces

  1. How to define an abstract class?
  2. What is a difference between abstract class and interface?
  3. When you to use abstract class and when interface?
  4. What is a default method in the interface?
  5. Since what versions of Java you can define default and private methods in the interface?
  6. Can I override static method?
  7. Can interface extend another interface?
  8. What is default modifiers for field and method in the interface?
  9. What is a marker interface?

Exceptions

  1. What is checked and unchecked exception?
  2. What is the difference between error and exception?
  3. What is exception hierarchy?
  4. How to handle exceptions?
  5. When To Use Checked and Unchecked Exceptions?
  6. is Error a checked or unchecked exception?
  7. Is Throwable a class or interface?
  8. Does Finally Block Executed If You Will Throw an Exception In Catch Block?
  9. Is OutOfMemory Error or Exception?

Collections (Data Structures)

  1. How ArrayList/LinkedList works inside?
  2. What is time complexity for adding/removing elements to the beginning/middle/end?
  3. What is a difference between LinkedList and ArrayList?
  4. How to remove elements from List in the loop?
  5. What is ConcurrentModificationException?
  6. Is ArrayList/LinkedList thread-safe?
  7. When it’s better to use ArrayList and when to use LinkedList?
  8. What interfaces LinkedList implements?
  9. How to make an immutable list?
  10. If I remove an element from ArrayList will internal array be reduced?
  11. What is default size of ArrayList?
  12. What is an internal implementation of HashMap?
  13. What are collisions and how HashMap handles it?
  14. What kind of object is better to use as a key and why? What happens if I change a field in a key object?
  15. What time complexity of get | put | remove operation? What happens in case of big amount of collisions?
  16. What was performance improvement made in HashMap in the scope of Java 8 release?
  17. What is a difference between HashMap and HashTable?
  18. What are a purpose of capacity and load factor in HashMap? What are default values? When is HashMap growing?
  19. What is a difference between HashMap and TreeMap?
  20. How to safely remove entries by value in HashMap?
  21. What is Set?
  22. What implementations of a Set do you know?
  23. What is a difference between HashSet and TreeSet?
  24. What is a time complexity of HashSet add | get | remove operations?
  25. What implementations of Queue do you know?
  26. What implementations of Deque do you know?
  27. How to sort an ArrayList?
  28. What is Iterator?

Resources

  1. Why is it necessary to close input/output streams?
  2. What is try-with-resources?
  3. What interface should I implement to use my object with a try-with-resources block?
  4. Why do we need BufferedInpuiStream/BufferedOutputStream?
  5. How to read a large file?

Memory

  1. What memory segments do you know?
  2. What was changed in memory segments in the scope of Java 8?
  3. What Heap areas do you know?
  4. How to calculate object memory usage?
  5. What is PermGen?
  6. What is Metaspace?

Multithreading and Concurrency

  1. What is a Thread?
  2. How to execute new Thread?
  3. What main components java.util.concurrency package do you know?
  4. What is wait(), notify() and notifyAll() mechanism? How does it work?
  5. What is a difference between synchronized and volatile?
  6. What is a requirement for wait(), notify() and notifyAll() usage?
  7. What could be a replacement for a wait() and notify() mechanism?
  8. What types of locks do you know?
  9. What is a ReentrantLock?
  10. What is a Condition?
  11. What is a difference between synchronized block and ReentrantLock?
  12. What is StampedLock?
  13. What are atomics?
  14. What is compareAndSet() and how does it work?
  15. How atomics work inside before Java 8 and after?
  16. What is thread pool?
  17. How many thread pools do you know? What is a difference?
  18. What are synchronizers in Java?
  19. What is CountDownLatch and how does it work?
  20. What is CyclicBarrier and how does it work?
  21. What is Exchanger and how does it work?
  22. What is Phaser and how does it work?
  23. What is Semaphor and how does it work?
  24. What is Future and how to execute it?
  25. What is CompletableFuture and why do we need it?
  26. What is ThreadJoinPool and when it’s better to use it?
  27. How to stop the thread?
  28. How to handle InterruptedException?
  29. What is a daemon thread?
  30. How to wait for another thread?
  31. What is a monitor object for non-static and for static methods?
  32. What is a Java Memory Model?
  33. What is volatile?
  34. I want to increment volatile field, is the operation thread-safe? What do I need to change to make it thread-safe?
  35. Is write/read operation with Long in 32-bit system atomic?
  36. What is a deadlock?
  37. How rules we need to use to avoid deadlocks?
  38. How to find deadlocks?
  39. What is livelock?
  40. What is ThreadLocal and how does it work?
  41. What is a ThreadFactory?
  42. What is a difference between Thread.yield() and Thread.sleep()?
  43. What is a difference between ConcurrentHashMap and Collections.synchronizedMap()?
  44. What is a difference between Thread.run() and Thread.start()?
  45. What is thread starvation?
  46. Can a synchronized block cause thread starvation?
  47. What is a race condition?
  48. What is a fair lock?

Concurrent Collections (Thread-Safe Data Structures)

  1. What is a thread-safe version of ArrayList?
  2. How to make List thread-safe?
  3. What is a difference ArrayList vs Vector vs CopyOnWriteArrayList?
  4. How CopyOnWriteArrayList works?
  5. What is a thread-safe version of HashMap?
  6. How to make Map thread-safe?
  7. What is a difference HashMap vs HashTable vs ConcurrentHashMap?
  8. What is a ConcurrentSkipListMap?
  9. What is a thread-safe version of HashSet?
  10. How to make Set thread-safe?
  11. What is a difference between ConcurrentSkipListSet and CopyOnWriteArraySet?
  12. What implementations of thread-safe Queue do you know?
  13. What implementations of thread-safe Deque do you know?

JDBC

  1. What is JDBC?
  2. How to connect to the database?
  3. What types of statements do you know?
  4. What is connection pool?
  5. How to create a transaction?
  6. What are transaction isolation levels?
  7. What is a database deadlock?

Garbage Collectors

  1. What is a Garbage Collector?
  2. What Garbage Collector implementations do you know?
  3. What is a difference between these garbage collectors?
  4. What is default collector in Java 8/9?
  5. How to configure Garbage Collector?
  6. What method can I use to run GC?
  7. What types of references do you know?
  8. What is a difference between SortReference and WeakReference?
  9. You need to implement the in-memory cache, what type of references is it better to use?
  10. What is a finalize() method?
  11. What is alternative for finalize() method?
  12. How phantom references work?
  13. What happens if finalize() method throw an exception?

XML and JSON

  1. What XML parsers do you know?
  2. What JSON parser do you know?

JSP and Servlets

  1. What variable scopes do you know in JSP?
  2. How does Servlet work?
  3. What Servlet methods do you know?
  4. Explain Servlet lifecycle
  5. What is a difference between includes <%@ include file=filename.jsp %> аnd < jsp:include page=filename.jsp />?
  6. What is Servlet Filter?
  7. What is web.xml?
  8. What is Servlet container?
  9. Is Servlet singleton or not?
  10. What is Session?
  11. What is Cookies?
  12. How does JSP work internally?

Design Patterns and Programming Principles

  1. What is template method design pattern?
  2. What is a difference between composite and composition?
  3. What design pattern is String.intern()?
  4. What design pattern is Collections.sort()?
  5. What is SOLID?
  6. What is coupling?
  7. What is cohesion?
  8. What is aggregation?
  9. What is a difference between composition and aggregation?
  10. What is DRY principle?
  11. What is KISS principle?
  12. What is ACID?
  13. What is CAP theorem?
  14. What is a singleton?
  15. What is abstract factory?
  16. What is a strategy?
  17. What is factory?
  18. What is a difference between proxy and adaptor?
  19. Could you provide examples of design patterns in Java Core?
  20. What is a builder?
  21. What is a mediator?

I want to ask you once again to leave your interview questions in comments and I’ll update my list.

Would be great for everyone to collect all Java interview questions here to make preparation for a new interview really faster and easier.

And don’t forget to add this page to your bookmarks!

Thanks!

Scroll Up