What is the difference between JDK, JRE and JVM?
Interview flashcards
174 questions collected from every lesson, from core Java to microservices. Try answering out loud before you reveal the model answer.
You know 0 of 174 questions.
Why is Java called platform independent?
What is autoboxing and what can go wrong?
Is var dynamic typing?
What is the difference between i++ and ++i?
What does short-circuit evaluation mean?
What is the difference between a switch statement and a switch expression?
What does yield do?
From Loops and arrays
Can you change an array's size?
From Loops and arrays
Array or ArrayList?
Is Java pass-by-reference for objects?
Overloading vs overriding?
Why is String immutable?
String vs StringBuilder vs StringBuffer?
Why does nextLine() return an empty string after nextInt()?
printf vs String.format?
Why not use double for money?
Random vs SecureRandom?
From Recursion
What causes StackOverflowError?
From Recursion
Recursion or iteration?
Can a constructor be private?
What is constructor chaining?
Can a static method access instance variables?
final, finally and finalize?
Why use packages?
What is package-private access?
What are the four pillars of OOP?
Why doesn't Java allow multiple inheritance of classes?
When would you pick an abstract class over an interface today?
Can an interface have a constructor?
Static nested vs inner class?
When is an anonymous class still useful instead of a lambda?
From Enums in depth
Can enums have constructors?
From Enums in depth
Why are enums good singletons?
What does a record generate automatically?
Why use sealed classes?
What happens if you override equals without hashCode?
Can two unequal objects have the same hashCode?
From Immutable objects
How do you make a class immutable?
From Immutable objects
unmodifiableList vs List.copyOf?
From Exception handling
Checked vs unchecked exceptions?
From Exception handling
Does finally always run?
ArrayList vs LinkedList?
HashSet vs LinkedHashSet vs TreeSet?
How does PriorityQueue order its elements?
Queue vs Deque?
Comparable vs Comparator?
What happens if compareTo is inconsistent with equals?
What happens when two keys have the same hashCode?
Why is the default load factor 0.75?
From Maps in practice
HashMap vs LinkedHashMap vs TreeMap?
From Maps in practice
How would you build an LRU cache in Java?
What is type erasure?
Explain PECS.
Why was java.time introduced?
Instant vs LocalDateTime?
java.io.File vs java.nio.file.Path?
How do you read a huge file without running out of memory?
From Regular expressions
matches() vs find()?
From Regular expressions
Why compile a Pattern once?
TCP vs UDP?
What does ServerSocket.accept() do?
What is a Locale used for?
How do resource bundles pick a file?
What is a functional interface?
Why must captured variables be effectively final?
From Stream API
Intermediate vs terminal operations?
From Stream API
map vs flatMap?
groupingBy vs partitioningBy?
How do you count items per group?
orElse vs orElseGet?
Should Optional be used for fields or parameters?
What is a guarded pattern?
How do sealed types and pattern matching work together?
From Modules (JPMS)
What does exports do in module-info.java?
From Modules (JPMS)
exports vs opens?
send vs sendAsync?
Why reuse a single HttpClient?
What is the time complexity of HashMap.get?
What does amortised O(1) mean?
Merge sort vs quick sort?
Which algorithm does Java use to sort objects?
How do you detect a cycle in a linked list?
When would you choose a linked list over an array list?
From Trees and graphs
BFS vs DFS?
From Trees and graphs
What does an in-order walk of a BST produce?
From Dynamic programming
Memoisation vs tabulation?
From Dynamic programming
When does a problem suit dynamic programming?
What makes a method clean?
When should you write a comment?
From SOLID principles
Explain the Liskov substitution principle with an example.
From SOLID principles
How does Spring help with dependency inversion?
How do you implement a thread-safe singleton in Java?
Builder vs telescoping constructors?
Strategy vs Template method?
Where is the observer pattern used in Spring?
What are Maven dependency scopes?
What does mvn install do?
Why use SLF4J instead of System.out.println?
What is MDC?
What is the Arrange-Act-Assert pattern?
What makes a good unit test?
From Mocking with Mockito
Mock vs stub vs spy?
From Mocking with Mockito
What shouldn't you mock?
How do you read a Java stack trace?
What is a conditional breakpoint?
What are the annotation retention policies?
Why is reflection considered risky or expensive?
From JSON with Jackson
Serialisation vs deserialisation?
From JSON with Jackson
How do you handle unknown fields from an external API?
Runnable vs Callable?
What happens if you never shut down an ExecutorService?
synchronized vs volatile?
How do you prevent deadlock?
CountDownLatch vs CyclicBarrier?
How does AtomicInteger stay thread-safe without locks?
From CompletableFuture
thenApply vs thenCompose?
From CompletableFuture
Future vs CompletableFuture?
From Virtual threads
Virtual vs platform threads?
From Virtual threads
Do virtual threads make code faster?
Stack vs heap?
What are GC roots?
ClassNotFoundException vs NoClassDefFoundError?
What is the parent delegation model?
Statement vs PreparedStatement?
Why use a connection pool?
Is Hibernate the same as JPA?
What does Spring Data JPA add?
What is the owning side of a relationship?
What are JPA's default fetch types?
What is dirty checking?
persist vs merge?
What is the N+1 select problem?
Why not just use FetchType.EAGER?
Why doesn't @Transactional work on self-invocation?
Optimistic vs pessimistic locking?
Why is constructor injection preferred?
@Component vs @Bean?
Is a singleton bean thread-safe?
What happens when you inject a prototype bean into a singleton?
How does Spring implement AOP?
Which advice type can change the return value or skip the method?
Explain the Spring MVC request flow.
@Controller vs @RestController?
What does @SpringBootApplication do?
How does auto-configuration work?
@Value vs @ConfigurationProperties?
How do profiles work?
How does Spring Data create repository implementations?
Page vs Slice?
PUT vs PATCH?
How do you handle exceptions globally in Spring Boot?
Authentication vs authorization?
How is a JWT validated?
@SpringBootTest vs @WebMvcTest?
Why use Testcontainers instead of H2?
@Cacheable vs @CachePut?
Local cache vs Redis?
fixedRate vs fixedDelay?
Why might @Async not work?
When would you not use microservices?
Why a database per service?
What does an API gateway do?
Client-side vs server-side discovery?
When would you choose Kafka over REST between services?
How does Kafka guarantee ordering?
Explain the circuit breaker states.
Why add jitter to retries?
What is the saga pattern?
Choreography vs orchestration?
Liveness vs readiness probe?
What is distributed tracing?
CI vs CD?
How do you handle secrets in a pipeline?