Java interview questions
BetaCore language, collections, generics, streams, concurrency primitives and the JVM basics.
Subtopics
- Primitives, wrappers & autoboxing6
- equals, hashCode & immutability7
- Collections framework8
- Generics & wildcards6
- Streams & lambdas8
- Exceptions & try-with-resources8
- Interfaces, abstract classes & records7
- Optional & null handling6
- Threads, executors & synchronization6
- JVM memory & garbage collection6
- Strings & StringBuilder6
- Enums & switch expressions6
Sample questions
- CodingJuniorCollections framework
Implement
entryPoint(List<String> words)that returns aMap<String, Integer>telling how many times each word occurs. The comparison is exact (case-sensitive).nullentries are ignored. - CodingJuniorCollections framework
Simulate a least-recently-used cache.
entryPoint(List<Integer> accesses, int capacity)receives the sequence of keys that were accessed, in order. The cache holds at mostcapacitykeys; when a new key does not fit, the least recently accessed key is evicted. Accessing a key that is - TheoryJuniorCollections framework
In one or two sentences each: what is a
List, what is aSet, and what is aMap? Give me one everyday situation where you would pick each one. - TheoryJuniorCollections framework
Compare
ArrayListandLinkedList. Which operations are cheap on each, and why isArrayListalmost always the right default even for workloads with insertions in the middle? - CodingJuniorEnums & switch expressions
Define an enum
Daywith the seven days of the week (MONDAYthroughSUNDAY) and a methodboolean isWeekend()that returnstrueforSATURDAYandSUNDAYandfalsefor the rest, implemented with a modern arrow-formswitchexpression (not a chain - TheoryJuniorEnums & switch expressions
What is a Java
enum, really, under the hood? Why is it preferred over a set ofpublic static final intconstants for something like a set of days of the week?