Top 20 Java Interview Questions and Answers for Freshers in 2025

Here are some common Java interview questions and simple answers for freshers:



1. What is Java?

Answer:
Java is a high-level, object-oriented programming language. It is platform-independent because of its "Write Once, Run Anywhere" capability.


2. What are the features of Java?

Answer:

  • Platform-independent
  • Object-oriented
  • Secure
  • Robust
  • Multithreaded
  • High performance
  • Dynamic

3. What is the JDK, JRE, and JVM?

Answer:

  • JDK (Java Development Kit): A toolkit for developing Java applications.
  • JRE (Java Runtime Environment): It runs Java programs.
  • JVM (Java Virtual Machine): Executes Java bytecode.

4. What is the difference between "== " and ".equals()" in Java?

Answer:

  • == checks if two objects reference the same memory location.
  • .equals() checks if two objects have the same value.

5. What are OOP principles in Java?

Answer:

  • Encapsulation: Protect data with access modifiers.
  • Inheritance: Reuse properties of a parent class.
  • Polymorphism: Perform tasks in different ways (method overloading/overriding).
  • Abstraction: Hide details and show only the essential features.

6. What is a constructor?

Answer:
A constructor is a special method used to initialize objects. It has the same name as the class and no return type.


7. What is the difference between method overloading and overriding?

Answer:

  • Overloading: Same method name but different parameters.
  • Overriding: Redefining a method from the parent class in the child class.

8. What is the difference between Array and ArrayList?

Answer:

  • Array: Fixed size and supports primitive types.
  • ArrayList: Dynamic size and only supports objects.

9. What are access modifiers in Java?

Answer:

  • Public: Accessible everywhere.
  • Private: Accessible only within the class.
  • Protected: Accessible within the package and subclasses.
  • Default: Accessible within the package.

10. What is the "final" keyword in Java?

Answer:

  • Final class: Cannot be inherited.
  • Final method: Cannot be overridden.
  • Final variable: Its value cannot change.

11. What is the difference between abstract class and interface?

Answer:

  • Abstract Class: Can have abstract and concrete methods; supports inheritance.
  • Interface: Only abstract methods (default methods allowed in newer versions); supports multiple inheritance.

12. What is the use of the "this" keyword?

Answer:
this refers to the current object of the class.


13. What is Exception Handling?

Answer:
It is a mechanism to handle runtime errors using try, catch, finally, throw, and throws.


14. What are common exceptions in Java?

Answer:

  • NullPointerException
  • ArrayIndexOutOfBoundsException
  • ArithmeticException
  • ClassNotFoundException

15. What is a thread in Java?

Answer:
A thread is a lightweight process. Java provides multithreading to perform multiple tasks simultaneously.


16. What is garbage collection?

Answer:
Garbage collection automatically removes unused objects from memory.


17. What is the difference between String, StringBuffer, and StringBuilder?

Answer:

  • String: Immutable.
  • StringBuffer: Mutable and thread-safe.
  • StringBuilder: Mutable but not thread-safe.

18. What are wrapper classes in Java?

Answer:
They convert primitive data types into objects (e.g., int to Integer).


19. What is the difference between HashMap and HashSet?

Answer:

  • HashMap: Stores key-value pairs.
  • HashSet: Stores unique values without duplicates.

20. What is the "super" keyword?

Answer:
super refers to the immediate parent class's object, method, or constructor.

Comments

Popular posts from this blog

Spring Boot OpenAI Integration: Step-by-Step Guide

Orchestration-Based Saga Architecture and Spring Boot Microservices Implementation Guide

Spring Boot 3 + Angular 15 + Material - Full Stack CRUD Application Example