Basic Java Interview Questions

  • Q: What is Java?

    A: Java is a platform-independent, object-oriented programming language.

  • Q: Explain JVM, JRE, and JDK.

    A: JVM runs bytecode, JRE = JVM + libraries, JDK = JRE + development tools.

  • Q: What is a class?

    A: Blueprint for objects.

  • Q: What is an object?

    A: Instance of a class.

  • Q: What are access modifiers?

    A: public, private, protected, default.

  • Q: What is a constructor?

    A: Initializes object during creation.

  • Q: Difference between == and equals()

    A: == compares references; equals() compares values.

  • Q: What is method overloading?

    A: Same method name, different parameters.

  • Q: What is method overriding?

    A: Child class redefines parent method.

  • Q: What is inheritance?

    A: Child class inherits parent class properties.

  • Q: What is polymorphism?

    A: Same method, different behavior.

  • Q: What is abstraction?

    A: Hiding internal implementation.

  • Q: What is encapsulation?

    A: Hiding data with private fields and public getters/setters.

  • Q: What is an interface?

    A: Abstract type defining methods a class must implement.

  • Q: What is an abstract class?

    A: Class with abstract methods (no body).

  • Q: What is final keyword?

    A: Prevents modification of class, method, or variable.

  • Q: Difference between static and instance methods?

    A: Static belongs to class; instance belongs to object.

  • Q: What is a package?

    A: Group of related classes.

  • Q: What is exception handling?

    A: Handling runtime errors with try-catch.

  • Q: Difference between checked and unchecked exceptions?

    A: Checked at compile-time, unchecked at runtime.

  • Q: What is a thread?

    A: Lightweight process.

  • Q: How to create a thread?

    A: Extend Thread class or implement Runnable.

  • Q: What is synchronization?

    A: Prevents multiple threads from accessing critical section.

  • Q: What is String in Java?

    A: Immutable sequence of characters.

  • Q: Difference between String, StringBuffer, StringBuilder?

    A: String immutable, StringBuffer thread-safe, StringBuilder faster.

  • Q: What is ArrayList?

    A: Resizable array.

  • Q: Difference between ArrayList and LinkedList?

    A: ArrayList faster for indexing, LinkedList better for inserts/deletes.

  • Q: What is HashMap?

    A: Key-value pair collection.

  • Q: What is garbage collection?

    A: Automatic memory cleanup.

  • Q: What is wrapper class?

    A: Converts primitive to object.

  • Q: What is autoboxing/unboxing?

    A: Auto conversion between primitives and objects.

  • Q: What is this keyword?

    A: Refers to current object.

  • Q: What is super keyword?

    A: Refers to parent class.

  • Q: Can a class have multiple constructors?

    A: Yes (constructor overloading).

  • Q: What is the main method signature?

    A: public static void main(String[] args)

  • Q: Can you override static method?

    A: No.

  • Q: Can abstract class have constructor?

    A: Yes.

  • Q: What is instanceof operator?

    A: Checks object type at runtime.

  • Q: What is a static block?

    A: Executes once when class loads.

  • Q: What is a singleton class?

    A: Class with single instance.

  • Q: What are varargs?

    A: Variable-length arguments.

  • Q: Can interface have constructors?

    A: No.

  • Q: What is default method in interface?

    A: Method with body in interface (Java 8+).

  • Q: What is toString()?

    A: Converts object to string.

  • Q: What is equals() and hashCode()?

    A: Defines object equality and hash.

  • Q: Difference between throw and throws?

    A: throw for exceptions; throws for method signature.

  • Q: What is try-with-resources?

    A: Automatic resource management (ARM).

  • Q: What is Enum?

    A: Special class with fixed set of constants.

  • Q: What is functional interface?

    A: Interface with exactly one abstract method.

  • Q: What is lambda expression?

    A: Concise way to pass code as parameter.

  • Q: What is stream in Java?

    A: Sequence of elements supporting functional operations.