NewWork mode: your Claude Code or Codex on work calls, answering from your project's codeSkip to content

Quiz: Java

Java questions from real interviews as a quiz, with an explanation for every option.

32 questionsAll topicsJava

Try it: 5 questions

Loading…

Sample questions

  1. What is the primary role of HandlerMapping in Spring MVC?

    • Check whether the user is authorized to make the request
    • Convert a controller's response into an HTML page
    • Invoke the selected controller method
    • Map an incoming HTTP request to the appropriate handler
    Full answer
  2. Which mechanisms can enforce a database constraint that depends on values from multiple columns? Select all that apply.

    • Checking values only in Java before saving
    • A CHECK constraint whose condition evaluates multiple columns
    • A composite UNIQUE constraint over a combination of columns
    • A composite PRIMARY KEY made up of multiple columns
    • A separate UNIQUE constraint on each column
    Full answer
  3. What does flatMap do when processing a stream of lists, such as Stream<List<String>>?

    • Processes each list in a separate parallel thread.
    • Converts each list into another list while preserving the nested structure.
    • Keeps only lists that contain elements of a specified type.
    • Converts each list to a stream and combines the elements into one flat stream.
    Full answer
  4. Why does the JVM create and store class metadata in Metaspace when the bytecode is already in a JAR file?

    • Metaspace preserves classes after the JVM exits so they can be reused on the next run without loading them from the JAR.
    • The JVM executes classes directly from Metaspace to read bytecode faster, without creating runtime structures.
    • The JVM uses a runtime representation of classes, such as method metadata and the runtime constant pool; the JAR remains an archive on disk.
    • A JAR contains only compiled bytecode, while Metaspace contains only the classes' static fields.
    Full answer
  5. How is a linked list organized, and how does accessing its elements differ from accessing array elements?

    • Nodes store data and links to neighboring nodes; accessing an element by index usually requires traversing the list.
    • Each node is linked to every other node, making access to any element take O(1).
    • Each node stores the index of the next element, while the data itself is kept in a separate array.
    • Elements occupy a contiguous block of memory, so access by index takes O(1).
    Full answer
  6. Which command can obtain a thread dump from a JVM process when its PID is known?

    • javac <PID>
    • jstack <PID>
    • jmap <PID>
    • jstat <PID>
    Full answer
  7. Which statements accurately describe how most modern LLMs work? Select all that apply.

    • Text is processed as a sequence of tokens, represented internally as numbers.
    • During generation, the model repeatedly chooses the next token based on a probability distribution.
    • Each token has a fixed meaning that the model processes independently of context.
    • During training, the model learns to predict the next token given the preceding context.
    • The model looks up every answer in an explicit fact database stored inside it.
    Full answer
  8. What is the correct general order for running tasks using a ThreadPoolExecutor-based pool?

    • Create the pool, call shutdown, then submit tasks with submit.
    • Pass tasks to the pool constructor, then call execute with no arguments.
    • Create the pool, submit tasks with execute or submit, then call shutdown.
    • Create a separate thread for each task, and use the pool only to stop them.
    Full answer
  9. Which standard Java exception most specifically indicates that a network connection could not be established?

    • InterruptedException
    • NullPointerException
    • FileNotFoundException
    • ConnectException
    Full answer
  10. Which statement correctly describes the main difference between a binary tree and a B-tree?

    • A binary-tree node has at most two children, while a B-tree node can hold multiple keys and have more than two children.
    • A binary-tree node can hold multiple keys, while a B-tree node has at most two children.
    • A binary tree is always balanced, while a B-tree can become unbalanced after insertions.
    • Both trees limit each node to two children, but only a B-tree stores keys in sorted order.
    Full answer