Languages

Java interview questions

Beta

Core language, collections, generics, streams, concurrency primitives and the JVM basics.

80 questions · 40 theory · 40 coding

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 a Map<String, Integer> telling how many times each word occurs. The comparison is exact (case-sensitive). null entries 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 most capacity keys; 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 a Set, and what is a Map? Give me one everyday situation where you would pick each one.

  • TheoryJuniorCollections framework

    Compare ArrayList and LinkedList. Which operations are cheap on each, and why is ArrayList almost always the right default even for workloads with insertions in the middle?

  • CodingJuniorEnums & switch expressions

    Define an enum Day with the seven days of the week (MONDAY through SUNDAY) and a method boolean isWeekend() that returns true for SATURDAY and SUNDAY and false for the rest, implemented with a modern arrow-form switch expression (not a chain

  • TheoryJuniorEnums & switch expressions

    What is a Java enum, really, under the hood? Why is it preferred over a set of public static final int constants for something like a set of days of the week?