Zalando technical round: Java, JVM and concurrency 9 questions in 4 chapters
- 01Memory model and concurrency3 questions
- 02Values, collections and trees5 questions
- 03JVM internals
- 04Sources
Memory model and concurrency
Visibility and ordering, bounded thread pools, and when read-write locks and blocking queues pay off.
1.1 What is the Java Memory Model, and what does happens-before guarantee? Medium 3 min
The memory model defines when one thread's writes become visible to another. Without a happens-before edge, the compiler and CPU may reorder or cache values, so a thread can see stale or half-published data. Edges come from program order, unlocking then locking the same monitor, a volatile write then a read of it, starting and joining threads, and final fields set in a constructor.
Read the full answer1.2 How do you size and configure a thread pool for a backend service? Medium 4 min
I use a bounded ThreadPoolExecutor rather than unbounded factories. I pick core and maximum sizes from the work: near the core count for CPU-bound tasks, larger for blocking I/O, then confirm by measuring. A bounded queue gives backpressure, and a rejection policy says what happens when it is full. I shut it down in order and make tasks respond to interruption.
Read the full answer1.3 When do ReadWriteLock and BlockingQueue help? Medium 2 min
A read-write lock lets many readers proceed together while a writer gets exclusive access, so it helps when reads vastly outnumber writes and each read takes a while. Otherwise a plain lock is simpler and often faster. A blocking queue is the standard producer-consumer handoff: producers put, consumers take, and a bounded capacity gives you backpressure.
Read the full answer
Values, collections and trees
Immutability, the complexity of the core collections, balanced trees and tries.
2.1 Why prefer immutable objects, and how is an unmodifiable view different from an immutable copy? Medium 3 min
Immutable objects can be shared between threads without locks once they are safely published, and they make reasoning and caching easier. An unmodifiable view, like Collections.unmodifiableList, only blocks writes through that reference; if someone changes the backing list, the view changes too. An immutable copy, like List.copyOf, owns its data. To make a class immutable, copy mutable inputs and never expose them.
Read the full answer2.2 What are the costs of ArrayList, LinkedList, HashMap and TreeMap, and how do you choose? Easy 5 min
ArrayList gives constant-time index access and amortized constant-time append, but inserting in the middle shifts elements. LinkedList only wins when you already hold the position, and it has poor cache behaviour. HashMap gives expected constant-time get and put without order; TreeMap gives guaranteed log n and keeps keys sorted. Pick the contract you need, then check the cost.
Read the full answer2.3 Why do balanced search trees matter, and when do you pick TreeMap over HashMap? Medium 3 min
A binary search tree finds a key in time proportional to its height. Insert sorted keys into a plain one and the height becomes n, so lookups turn linear. Balanced trees such as red-black trees keep the height logarithmic. Java's TreeMap is one, with guaranteed log n operations and sorted keys. I choose it when I need order or ranges, and HashMap otherwise.
Read the full answer2.4 What is a trie, and how would you code prefix autocomplete in Java? Medium 4 min
A trie stores strings by shared prefix: each edge is a character, and a node marks where a word ends. Finding all words with a prefix costs the prefix length plus the nodes you visit, regardless of how many other words exist. The cost is memory, one node per character. For a compact read-only dictionary, search engines use finite-state transducers instead.
Read the full answer2.5 How do you find two numbers that sum to k in a rotated sorted array? Medium 3 min
A hash set solves it in one pass with linear time and space. To use constant space, I find the rotation point with binary search, which is the index of the smallest element. Then I run the usual two-pointer search, starting at the smallest and the largest elements and moving the pointers around the array with modulo arithmetic. That keeps linear time and constant extra space.
Read the full answer
JVM internals
How classes are loaded, and how to read class-loading errors.
3.1 How do JVM class loaders work, and what do ClassNotFoundException and NoClassDefFoundError tell you? Medium 3 min
Class loaders find class bytes and define classes. Java has three built-in ones: bootstrap for the core platform, platform for the rest of the Java SE modules, and the application loader for the class path. Each loader asks its parent first, so core classes cannot be replaced. ClassNotFoundException means an explicit lookup failed; NoClassDefFoundError means a class that existed at compile time is missing at run time.
Read the full answer
Sources
Source: Zalando Engineering: Interview preparation tips for Java developers (June 2016) Source: LeetCode Discuss: Zalando C6 Backend Engineer, Berlin (candidate report, May 2022) Source: Zalando Jobs: Senior Search Engineer, Search and Browse Core (job ad) Source: JLS 21 chapter 17: Threads and Locks (memory model, happens-before, final fields) Source: ThreadPoolExecutor Javadoc (Java 21) Source: Executors Javadoc (Java 21) Source: ReentrantReadWriteLock Javadoc (Java 21) Source: BlockingQueue Javadoc (Java 21) Source: Collections Javadoc (Java 21): unmodifiable views Source: List Javadoc (Java 21): unmodifiable lists from List.of and List.copyOf Source: ArrayList Javadoc (Java 21) Source: LinkedList Javadoc (Java 21) Source: HashMap Javadoc (Java 21) Source: TreeMap Javadoc (Java 21): red-black tree, guaranteed log(n) Source: Lucene 9.11 org.apache.lucene.util.fst package Source: Manning, Raghavan and Schütze: Introduction to Information Retrieval (Cambridge University Press, 2008) Source: JEP 248: Make G1 the Default Garbage Collector Source: LeetCode 153: Find Minimum in Rotated Sorted Array (problem statement) Source: Callable Javadoc (Java 21) Source: Java Cryptography Architecture Reference Guide (Java 21): why passwords are collected in char arrays Source: ArrayList Javadoc (Java 21): fail-fast iterators Source: CopyOnWriteArrayList Javadoc (Java 21): snapshot iterators Source: java.util.concurrent package summary (Java 21): weakly consistent iterators Source: HashSet Javadoc (Java 21): backed by a HashMap Source: HashMap Javadoc (Java 21): capacity, load factor and rehashing Source: Elasticsearch docs: Suggesters (completion suggester) Source: ClassLoader Javadoc (Java 21): delegation model and built-in class loaders Source: JVM Specification SE 21, chapter 5: Loading, Linking, and Initializing Source: NoClassDefFoundError Javadoc (Java 21) Source: Spring Boot reference: The executable JAR format