H
HireZone Verified Jobs • Free ATS Tools
Interview Prep ⏱ 18 min read ✓ Verified Editorial Guide

Top 50 Core Java & Spring Boot Interview Questions for Freshers (With Code Examples)

Master the 50 most frequently asked Java and Spring Boot technical interview questions for freshers, complete with code snippets, OOP concepts, and memory explanations.

H
HireZone Editorial Team
Senior Career & Placement Advisor • Updated Sep 20, 2026

Top 50 Core Java & Spring Boot Interview Questions for Freshers

Java remains the most heavily tested programming language across Indian campus placements and off-campus drives (TCS, Infosys, Cognizant, Wipro, Accenture, Deloitte). Here are the foundational questions, explanations, and code examples you must master.

---

Part 1: Core Java Fundamentals

1. What is the difference between JDK, JRE, and JVM?

  • JVM (Java Virtual Machine): The execution engine that executes Java bytecode (.class files). JVM provides platform independence by converting bytecode into native machine code.
  • JRE (Java Runtime Environment): JVM + Core Libraries required to run Java applications. It does NOT include compilers or debuggers.
  • JDK (Java Development Kit): JRE + Development Tools (such as javac compiler, javadoc, and jdb debugger). Developers require the JDK to write and compile code.

2. Why is String immutable in Java?

Strings in Java are immutable (cannot be changed once created) for three vital reasons:
  • String Constant Pool (SCP): Stored in the heap memory to save RAM. If strings were mutable, changing one reference would silently alter all other variables pointing to the same literal.
  • Security: Strings are widely used for database URLs, usernames, passwords, and network sockets. Immutability prevents tampering.
  • Thread Safety: Immutable objects are inherently thread-safe and can be shared freely across multiple threads without synchronization.
String s1 = "Hello";
s1.concat(" World");
System.out.println(s1); // Prints "Hello" (Original string unmodified)

String s2 = s1.concat(" World");
System.out.println(s2); // Prints "Hello World"

3. Difference between == and .equals()?

  • == is a reference comparison operator. It checks whether both references point to the exact same memory address.
  • .equals() is a method in the Object class. By default, it checks references, but classes like String, Integer, and Date override it to perform value/content comparison.
String a = new String("Java");
String b = new String("Java");
System.out.println(a == b);      // false (different heap objects)
System.out.println(a.equals(b));  // true (same textual content)

4. What is the difference between ArrayList and LinkedList?

FeatureArrayListLinkedList
Internal Data StructureResizable Dynamic ArrayDoubly Linked List
Get / Lookup by IndexO(1) Constant TimeO(n) Linear Time
Insert / Delete at beginningO(n) (Shifting required)O(1) Pointer update
Memory ConsumptionLow (Stores only elements)Higher (Stores data + 2 pointers per node)

5. How does HashMap work internally in Java?

HashMap works on the principle of Hashing.
  • When map.put(key, value) is called, Java calculates key.hashCode().
  • The hash code is converted to an index in the internal bucket array: index = hash & (n-1).
  • If no collision occurs, the entry is stored in a Node.
  • If a collision occurs (two keys yield the same index), entries are stored in a linked list.
  • In Java 8+, if the number of colliding nodes in a bucket exceeds 8 (TREEIFY_THRESHOLD), the linked list is automatically converted into a balanced Red-Black Tree, reducing worst-case lookup from O(n) to O(log n).
---

Part 2: Object-Oriented Programming (OOP)

6. What is the difference between Method Overloading and Method Overriding?

  • Overloading: Same method name, different parameters within the same class. Resolved at compile-time (Static polymorphism).
  • Overriding: Same method name, identical parameters in a child class. Resolved at runtime (Dynamic method dispatch).
class Calculator {
    // Overloading
    int add(int a, int b) { return a + b; }
    double add(double a, double b) { return a + b; }
}

class Animal {
void speak() { System.out.println("Animal speaks"); }
}
class Dog extends Animal {
// Overriding
@Override
void speak() { System.out.println("Dog barks"); }
}

---

Part 3: Spring Boot Essentials

7. What are the key advantages of Spring Boot over standard Spring Framework?

  • Auto-Configuration: Automatically configures beans based on dependencies present on the classpath.
  • Embedded Servers: Bundles Tomcat, Jetty, or Undertow inside the JAR, eliminating manual WAR deployments.
  • Starter Dependencies: Simplifies Maven/Gradle dependency management (e.g., spring-boot-starter-web).
  • Production-Ready Actuators: Out-of-the-box health checks, metrics, and application monitoring.

8. Explain the Spring Bean Lifecycle.

  • Bean Definition loaded from annotations or XML.
  • Bean Instantiation (Constructor invoked).
  • Dependency Injection (Properties populated via @Autowired).
  • Custom Init methods called (@PostConstruct or InitializingBean.afterPropertiesSet()).
  • Bean is ready for use.
  • Container shutdown -> Destroy methods called (@PreDestroy or DisposableBean.destroy()).

Prepare Your Resume for Top Tech Companies

Before applying, verify that your resume passes Automated Tracking Systems (ATS) used by TCS, Infosys, Accenture, and Wipro. Use our free suite of applicant tools:

Related Preparation Roadmaps & Guides

Interview Prep

Top 35 SQL Query & Database Interview Questions for Data Analysts & Freshers

Comprehensive SQL interview cheat sheet for freshers. Covers Joins, Window Functions, Subqueries, No...

Read Guide →
Interview Prep

Deloitte National Level Off-Campus Hiring Guide: Aptitude, Versant English & Technical Rounds

Complete blueprint for clearing Deloitte off-campus hiring drives. Covers online assessment syllabus...

Read Guide →
Exam Syllabus

TCS NQT 2026 Complete Preparation Blueprint: Exam Pattern, Sectional Cutoffs & Coding Questions

Comprehensive guide to cracking TCS National Qualifier Test (NQT) 2026. Covers Ninja, Digital, and P...

Read Guide →