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. Can a try block exist without a catch block in Java?

    Yes, as long as it has either a finally block or resources in try-with-resources. A bare try with neither is a compile error.

    BeginnerQuick answer1 min read
  2. What are the four pillars of object-oriented programming in Java?

    Encapsulation hides data behind methods, abstraction exposes only what matters, inheritance reuses a parent class, and polymorphism lets one call behave differently depending on the actual object.

    BeginnerQuick answer1 min read
  3. What is the difference between throw and throws in Java?

    throw is a statement that actually raises one exception object at that moment. throws is part of a method signature that warns callers which checked exceptions the method might pass on.

    BeginnerQuick answer1 min read
  4. Why is the main method public static void in Java?

    public so the JVM can call it from outside, static so it can run without creating an object, void because the JVM does not use a return value, and String[] args carries the command-line arguments.

    BeginnerQuick answer1 min read