Interview Q&A / Java

INTERVIEW Q&A · 72 QUESTIONS

Java interview questions

Collections, the JVM, strings, exceptions and threads, the backbone of most campus placement rounds.

  1. What is the difference between orElse and orElseGet in Java Optional?

    orElse takes a ready value that is always evaluated, even when the Optional has a value. orElseGet takes a Supplier that runs only when the Optional is empty, so use it when the fallback is expensive or has side effects.

    IntermediateQuick answer1 min read