<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: abhijit maharik</title>
    <description>The latest articles on DEV Community by abhijit maharik (@abhijit_maharik_3b36da1a8).</description>
    <link>https://dev.to/abhijit_maharik_3b36da1a8</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1716643%2F8b8454f2-c176-4bfa-949e-42bbfb473f57.jpg</url>
      <title>DEV Community: abhijit maharik</title>
      <link>https://dev.to/abhijit_maharik_3b36da1a8</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abhijit_maharik_3b36da1a8"/>
    <language>en</language>
    <item>
      <title>Top 25 Java Collections Interview Questions for Wipro and Capgemini — With Answers (2025)</title>
      <dc:creator>abhijit maharik</dc:creator>
      <pubDate>Sun, 05 Apr 2026 16:40:23 +0000</pubDate>
      <link>https://dev.to/abhijit_maharik_3b36da1a8/top-25-java-collections-interview-questions-for-wipro-and-capgemini-with-answers-2025-19k4</link>
      <guid>https://dev.to/abhijit_maharik_3b36da1a8/top-25-java-collections-interview-questions-for-wipro-and-capgemini-with-answers-2025-19k4</guid>
      <description>&lt;p&gt;Wipro and Capgemini interviews often follow a pattern: after basic Java questions they go deep into Collections — how they work, when to use which one, and why. This post collects the 25 most-asked Collections questions with short, clear answers and code examples. Read this the night before your interview and you’ll walk in confident.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;1. What is the Java Collections Framework?&lt;/li&gt;
&lt;li&gt;2. What is the difference between Collection and Collections?&lt;/li&gt;
&lt;li&gt;3. What is the difference between ArrayList and LinkedList?&lt;/li&gt;
&lt;li&gt;4. What is the difference between ArrayList and Vector?&lt;/li&gt;
&lt;li&gt;5. What is the difference between HashSet, LinkedHashSet and TreeSet?&lt;/li&gt;
&lt;li&gt;6. What is the difference between HashMap and Hashtable?&lt;/li&gt;
&lt;li&gt;7. What is the difference between HashMap and LinkedHashMap?&lt;/li&gt;
&lt;li&gt;8. How does HashMap work internally?&lt;/li&gt;
&lt;li&gt;9. What is the difference between HashMap and TreeMap?&lt;/li&gt;
&lt;li&gt;10. What is the difference between Iterator and ListIterator?&lt;/li&gt;
&lt;li&gt;11. What is ConcurrentModificationException and how do you avoid it?&lt;/li&gt;
&lt;li&gt;12. What is the difference between fail-fast and fail-safe iterators?&lt;/li&gt;
&lt;li&gt;13. What is a PriorityQueue in Java?&lt;/li&gt;
&lt;li&gt;14. What is the difference between Queue and Deque?&lt;/li&gt;
&lt;li&gt;15. What is the difference between Stack and ArrayDeque?&lt;/li&gt;
&lt;li&gt;16. What is Collections.sort() and how does it work?&lt;/li&gt;
&lt;li&gt;17. What is the difference between Comparable and Comparator?&lt;/li&gt;
&lt;li&gt;18. What is an unmodifiable collection?&lt;/li&gt;
&lt;li&gt;19. What is the difference between List.of() and Arrays.asList()?&lt;/li&gt;
&lt;li&gt;20. What is CopyOnWriteArrayList?&lt;/li&gt;
&lt;li&gt;21. What is ConcurrentHashMap?&lt;/li&gt;
&lt;li&gt;22. What is the difference between peek(), poll() and remove() in Queue?&lt;/li&gt;
&lt;li&gt;23. How do you synchronize an ArrayList?&lt;/li&gt;
&lt;li&gt;24. What is the initial capacity and load factor of HashMap?&lt;/li&gt;
&lt;li&gt;25. What is the difference between keySet(), values() and entrySet() in HashMap?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  1. What is the Java Collections Framework?
&lt;/h2&gt;

&lt;p&gt;The Java Collections Framework is a set of classes and interfaces that provide ready-made data structures like lists, sets, queues, and maps. It lives in the java.util package and eliminates the need to build your own data structures from scratch. Every Java developer uses it daily — which is exactly why interviewers ask about it.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. What is the difference between Collection and Collections?
&lt;/h2&gt;

&lt;p&gt;Collection is an interface — the root of the collection hierarchy that List, Set, and Queue extend. Collections is a utility class with static helper methods like sort(), shuffle(), reverse(), and synchronizedList(). Think of Collection as the blueprint and Collections as the toolbox.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. What is the difference between ArrayList and LinkedList?
&lt;/h2&gt;

&lt;p&gt;ArrayList stores elements in a dynamic array — fast for random access but slow for insertions and deletions in the middle. LinkedList stores elements as nodes with pointers — fast for insertions and deletions but slow for random access. Use ArrayList for most cases and LinkedList only when you insert or delete frequently at the beginning or middle.&lt;/p&gt;

&lt;p&gt;java&lt;br&gt;
// ArrayList — fast get by index&lt;br&gt;
List arrayList = new ArrayList&amp;lt;&amp;gt;();&lt;br&gt;
arrayList.add("TCS");&lt;br&gt;
arrayList.add("Wipro");&lt;br&gt;
String company = arrayList.get(1); // Fast — O(1)&lt;/p&gt;

&lt;p&gt;// LinkedList — fast add at beginning&lt;br&gt;
LinkedList linkedList = new LinkedList&amp;lt;&amp;gt;();&lt;br&gt;
linkedList.addFirst("Capgemini"); // Fast — O(1)&lt;/p&gt;

&lt;h2&gt;
  
  
  4. What is the difference between ArrayList and Vector?
&lt;/h2&gt;

&lt;p&gt;Both use dynamic arrays internally but Vector is synchronized — meaning it is thread-safe but slower. ArrayList is not synchronized — faster but not thread-safe for concurrent access. In modern Java, ArrayList with explicit synchronization or CopyOnWriteArrayList is preferred over Vector.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. What is the difference between HashSet, LinkedHashSet and TreeSet?
&lt;/h2&gt;

&lt;p&gt;HashSet stores elements in no particular order and allows no duplicates — fastest for basic operations. LinkedHashSet maintains insertion order while still preventing duplicates. TreeSet stores elements in natural sorted order — slowest of the three but useful when you need sorted unique elements.&lt;/p&gt;

&lt;p&gt;// HashSet — no order, no duplicates&lt;br&gt;
Set hashSet = new HashSet&amp;lt;&amp;gt;();&lt;br&gt;
hashSet.add("Wipro");&lt;br&gt;
hashSet.add("Capgemini");&lt;br&gt;
hashSet.add("Wipro"); // Duplicate ignored&lt;br&gt;
System.out.println(hashSet);&lt;/p&gt;

&lt;p&gt;// TreeSet — sorted (natural order)&lt;br&gt;
Set treeSet = new TreeSet&amp;lt;&amp;gt;();&lt;br&gt;
treeSet.add("Wipro");&lt;br&gt;
treeSet.add("Capgemini");&lt;br&gt;
treeSet.add("Accenture");&lt;br&gt;
System.out.println(treeSet); // [Accenture, Capgemini, Wipro]&lt;/p&gt;

&lt;h2&gt;
  
  
  6. What is the difference between HashMap and Hashtable?
&lt;/h2&gt;

&lt;p&gt;HashMap is not synchronized and allows one null key and multiple null values — faster for single-threaded use. Hashtable is synchronized and does not allow null keys or values — thread-safe but slower. In modern Java, use ConcurrentHashMap instead of Hashtable for thread-safe map operations.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. What is the difference between HashMap and LinkedHashMap?
&lt;/h2&gt;

&lt;p&gt;HashMap stores key-value pairs with no guaranteed order. LinkedHashMap maintains insertion order — elements come out in the same order you put them in. Use LinkedHashMap when order matters, like building a cache or maintaining a sequence of operations.&lt;/p&gt;

&lt;p&gt;import java.util.LinkedHashMap;&lt;br&gt;
import java.util.Map;&lt;/p&gt;

&lt;p&gt;Map linkedHashMap = new LinkedHashMap&amp;lt;&amp;gt;();&lt;br&gt;
linkedHashMap.put("first", 1);&lt;br&gt;
linkedHashMap.put("second", 2);&lt;br&gt;
linkedHashMap.put("third", 3);&lt;/p&gt;

&lt;p&gt;// Iterates in insertion order: first, second, third&lt;br&gt;
for (Map.Entry entry : linkedHashMap.entrySet()) {&lt;br&gt;
    System.out.println(entry.getKey() + " = " + entry.getValue());&lt;br&gt;
}&lt;/p&gt;

&lt;h2&gt;
  
  
  8. How does HashMap work internally?
&lt;/h2&gt;

&lt;p&gt;HashMap stores key-value pairs in an internal array of buckets (Node[] table). When you call put(key, value):&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Java computes a hash from key.hashCode() and “spreads” the bits.
The bucket index is index = (table.length - 1) &amp;amp; hash.
If the bucket is empty, the entry becomes the first node there.
If the bucket already has entries, entries are appended as a linked list (Node chain). In Java 8+, if a chain exceeds 8 nodes, it converts to a red-black tree.
HashMap resizes when size &amp;gt; loadFactor * capacity.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;import java.util.HashMap;&lt;br&gt;
import java.util.Map;&lt;/p&gt;

&lt;p&gt;Map map = new HashMap&amp;lt;&amp;gt;();&lt;br&gt;
map.put("name", "Abhijit");&lt;br&gt;&lt;br&gt;
map.put("city", "Odisha");    &lt;/p&gt;

&lt;p&gt;String name = map.get("name"); &lt;br&gt;
System.out.println(name);      // prints "Abhijit"&lt;/p&gt;

&lt;h2&gt;
  
  
  9. What is the difference between HashMap and TreeMap?
&lt;/h2&gt;

&lt;p&gt;HashMap provides O(1) average time for get and put operations but stores entries in no order. TreeMap stores entries sorted by key in natural order or by a custom comparator — but operations take O(log n) time. Use TreeMap when you need keys in sorted order.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What is the difference between Iterator and ListIterator?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Iterator can traverse any Collection in the forward direction only. ListIterator works only with List implementations, is bidirectional, and supports add() and set() operations.&lt;/p&gt;

&lt;p&gt;import java.util.ArrayList;&lt;br&gt;
import java.util.List;&lt;br&gt;
import java.util.ListIterator;&lt;/p&gt;

&lt;p&gt;List companies = new ArrayList&amp;lt;&amp;gt;(List.of("Wipro", "Capgemini", "TCS"));&lt;/p&gt;

&lt;p&gt;ListIterator iterator = companies.listIterator();&lt;br&gt;
while (iterator.hasNext()) {&lt;br&gt;
    String company = iterator.next();&lt;br&gt;
    if ("TCS".equals(company)) {&lt;br&gt;
        iterator.set("Infosys"); &lt;br&gt;
    }&lt;br&gt;
}&lt;br&gt;
System.out.println(companies); // [Wipro, Capgemini, Infosys]&lt;/p&gt;

&lt;h2&gt;
  
  
  11. What is ConcurrentModificationException and how do you avoid it?
&lt;/h2&gt;

&lt;p&gt;ConcurrentModificationException occurs when a collection is structurally modified while iterating over it using an iterator. To avoid it, use iterator.remove() instead of list.remove(), or use concurrent collections like CopyOnWriteArrayList.&lt;/p&gt;

&lt;p&gt;// Correct way to remove during iteration&lt;br&gt;
Iterator it = list.iterator();&lt;br&gt;
while (it.hasNext()) {&lt;br&gt;
    String s = it.next();&lt;br&gt;
    if ("B".equals(s)) {&lt;br&gt;
        it.remove(); // Safe&lt;br&gt;
    }&lt;br&gt;
}&lt;/p&gt;

&lt;h2&gt;
  
  
  12. What is the difference between fail-fast and fail-safe iterators?
&lt;/h2&gt;

&lt;p&gt;Fail-fast iterators (like ArrayList) throw ConcurrentModificationException if the collection is modified during iteration. Fail-safe iterators (like CopyOnWriteArrayList) work on a copy, so they don't throw the exception but use more memory.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What is a PriorityQueue in Java?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;PriorityQueue is a queue where elements are ordered by priority (natural ordering or custom comparator) rather than insertion order.&lt;/p&gt;

&lt;p&gt;Queue pq = new PriorityQueue&amp;lt;&amp;gt;();&lt;br&gt;
pq.add(30);&lt;br&gt;
pq.add(10);&lt;br&gt;
pq.add(20);&lt;br&gt;
System.out.println(pq.poll()); // 10 — smallest first&lt;/p&gt;

&lt;h2&gt;
  
  
  14. What is the difference between Queue and Deque?
&lt;/h2&gt;

&lt;p&gt;Queue is FIFO (First-In-First-Out). Deque (Double Ended Queue) allows adding/removing from both ends.&lt;/p&gt;

&lt;h2&gt;
  
  
  15. What is the difference between Stack and ArrayDeque?
&lt;/h2&gt;

&lt;p&gt;Stack is a legacy, synchronized class. ArrayDeque is modern, faster, and not synchronized. Java recommends ArrayDeque for stack operations.&lt;/p&gt;

&lt;h2&gt;
  
  
  16. What is Collections.sort() and how does it work?
&lt;/h2&gt;

&lt;p&gt;It sorts a List using a modified merge sort. It requires elements to implement Comparable or a Comparator.&lt;/p&gt;

&lt;h2&gt;
  
  
  17. What is the difference between Comparable and Comparator?
&lt;/h2&gt;

&lt;p&gt;Comparable defines "natural ordering" within the class itself (compareTo). Comparator is an external class used for custom sorting (compare).&lt;/p&gt;

&lt;h2&gt;
  
  
  18. What is an unmodifiable collection?
&lt;/h2&gt;

&lt;p&gt;A wrapper that prevents modification, throwing UnsupportedOperationException if add or remove is called.&lt;/p&gt;

&lt;h2&gt;
  
  
  19. What is the difference between List.of() and Arrays.asList()?
&lt;/h2&gt;

&lt;p&gt;List.of() (Java 9+) is truly immutable and doesn't allow nulls. Arrays.asList() is fixed-size but allows updating existing elements.&lt;/p&gt;

&lt;h2&gt;
  
  
  20. What is CopyOnWriteArrayList?
&lt;/h2&gt;

&lt;p&gt;A thread-safe List where every write creates a new copy of the array. Ideal for many reads and very few writes.&lt;/p&gt;

&lt;h2&gt;
  
  
  21. What is ConcurrentHashMap?
&lt;/h2&gt;

&lt;p&gt;A thread-safe Map that uses segment-level locking rather than locking the whole map, allowing higher concurrency than Hashtable.&lt;/p&gt;

&lt;h2&gt;
  
  
  22. What is the difference between peek(), poll() and remove() in Queue?
&lt;/h2&gt;

&lt;p&gt;peek() sees the head (returns null if empty). poll() removes the head (returns null if empty). remove() removes the head (throws exception if empty).&lt;/p&gt;

&lt;h2&gt;
  
  
  23. How do you synchronize an ArrayList?
&lt;/h2&gt;

&lt;p&gt;Use Collections.synchronizedList(). Remember to manually synchronize the block when iterating.&lt;/p&gt;

&lt;p&gt;List syncList = Collections.synchronizedList(new ArrayList&amp;lt;&amp;gt;());&lt;br&gt;
synchronized (syncList) {&lt;br&gt;
    for (String s : syncList) {&lt;br&gt;
        System.out.println(s);&lt;br&gt;
    }&lt;br&gt;
}&lt;/p&gt;

&lt;h2&gt;
  
  
  24. What is the initial capacity and load factor of HashMap?
&lt;/h2&gt;

&lt;p&gt;Default capacity is 16; default load factor is 0.75.&lt;/p&gt;

&lt;h2&gt;
  
  
  25. What is the difference between keySet(), values() and entrySet() in HashMap?
&lt;/h2&gt;

&lt;p&gt;keySet() returns keys, values() returns values, and entrySet() returns key-value pairs. entrySet() is the most efficient for iterating over both.&lt;/p&gt;

&lt;p&gt;Mastering Java Collections means understanding core interfaces, implementations, performance trade-offs, and internal mechanics. Study List, Set, Map variants, iteration patterns, and concurrency options; practice small, runnable examples and complexity analysis. With these fundamentals and the provided snippets, you’ll tackle Wipro/Capgemini interview questions confidently, justify choices, and write clear code effectively.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Revise core interfaces and implementations: List, Set, Map, Queue and their common concrete classes.

Be able to explain trade‑offs: time/space complexity, iteration costs, insertion/removal characteristics (e.g., ArrayList vs LinkedList, HashMap vs TreeMap).

Know internal mechanics for key classes (HashMap hashing/buckets, rehashing, fail‑fast iterators) and concurrency variants (synchronized wrappers, CopyOnWriteArrayList, ConcurrentHashMap).

Practice writing small examples — show you can code common operations and custom comparators/equals/hashCode correctly.

Memorize a short “cheat sheet” of typical Big‑O for common ops (search/insert/delete/access) for the main collections.

During interviews, explain your thought process: why you choose a collection, alternatives, and how you’d handle concurrency or large data.

Use entrySet() for efficient map iteration, prefer ArrayDeque over Stack, prefer List.of()/Collections.unmodifiableList() for immutable collections, and prefer list.sort(...) (Java 8+) when convenient.

Run mock interviews, solve collection‑focused coding problems, and re‑read relevant Javadocs or Effective Java items to solidify best practices.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Final tip: interviewers want clear reasoning and practical examples. If you can justify your choice and show a few concise code snippets, you’ll stand out. Good luck — go in calm, and let the collections do the talking.&lt;/p&gt;

</description>
      <category>java</category>
      <category>programming</category>
      <category>interview</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Top 30 Spring Boot Interview Questions Asked in TCS and Infosys — With Answers (2025)</title>
      <dc:creator>abhijit maharik</dc:creator>
      <pubDate>Wed, 01 Apr 2026 18:41:35 +0000</pubDate>
      <link>https://dev.to/abhijit_maharik_3b36da1a8/top-30-spring-boot-interview-questions-asked-in-tcs-and-infosys-with-answers-2025-2nfi</link>
      <guid>https://dev.to/abhijit_maharik_3b36da1a8/top-30-spring-boot-interview-questions-asked-in-tcs-and-infosys-with-answers-2025-2nfi</guid>
      <description>&lt;p&gt;&lt;em&gt;I work in government tech in Bhubaneswar and have spent years writing Java backend systems. When my colleagues started preparing for TCS and Infosys interviews, I noticed they were reading 50-page PDFs for answers that should take 3 sentences. So I wrote this — 30 real Spring Boot questions with short, honest answers. No padding. No theory lectures. Just what you actually need.&lt;/em&gt;&lt;br&gt;
&lt;strong&gt;Table of contents&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What is Spring Boot and how is it different from Spring Framework?

What is the purpose of @SpringBootApplication annotation?

What is Auto-Configuration in Spring Boot?

What is the difference between @Component, @Service, @Repository and @Controller?

What is Dependency Injection and how does Spring Boot implement it?

What is the difference between @RestController and @Controller?

What are Spring Boot Starters?

What is application.properties and what is it used for?

What is the difference between @GetMapping, @PostMapping, @PutMapping and @DeleteMapping?

How does Spring Boot connect to a database?

What is JPA and how is it used in Spring Boot?

What is a Spring Boot Repository and what is JpaRepository?

What is the difference between @PathVariable and @RequestParam?

What is Spring Security and how do you add it to Spring Boot?

What is JWT and how is it used with Spring Boot?

What is the difference between @Bean and @Component?

What is Actuator in Spring Boot?

What is the difference between @RequestBody and @ResponseBody?

What is a Microservice and how does Spring Boot support it?

What is @Transactional and when do you use it?

What is the difference between SOAP and REST?

What is Spring Boot DevTools?

What is the difference between findById() and getById() in JPA?

What is Lombok and why is it used in Spring Boot projects?

What is an Exception Handler in Spring Boot?

What is the difference between PUT and PATCH?

What is Connection Pooling and does Spring Boot support it?

What is the use of @Value annotation?

What is the difference between Spring Boot and Spring MVC?

What is an Embedded Server in Spring Boot?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;1. What is Spring Boot and how is it different from Spring Framework?&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Spring Boot is an opinionated layer on top of the Spring Framework that provides auto-configuration, starter dependencies, embedded servers, and production features so you can create runnable applications with minimal setup. Spring (the framework) provides the core IoC, AOP, data, and ecosystem; Spring Boot makes it easy to get a Spring application up and running quickly.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Example (main class):&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
@SpringBootApplication&lt;br&gt;
public class DemoApplication {&lt;br&gt;
    public static void main(String[] args) {&lt;br&gt;
        SpringApplication.run(DemoApplication.class, args);&lt;br&gt;
    }&lt;br&gt;
}&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;2. What is the purpose of @SpringBootApplication annotation?&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@SpringBootApplication is a convenience meta-annotation that combines @Configuration, @EnableAutoConfiguration, and @ComponentScan. Put it on your main class to enable auto-configuration, component scanning in the package and subpackages, and to declare configuration.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@SpringBootApplication&lt;br&gt;
public class MyApplication {&lt;br&gt;
    public static void main(String[] args) {&lt;br&gt;
        SpringApplication.run(MyApplication.class, args);&lt;br&gt;
    }&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. What is Auto-Configuration in Spring Boot?&lt;/strong&gt;&lt;br&gt;
Auto-configuration attempts to automatically configure your Spring application based on the dependencies present on the classpath and sensible defaults. You can override auto-configuration by defining your own beans or by excluding specific auto-configuration classes.&lt;/p&gt;

&lt;p&gt;Example: Let Spring Boot create a DataSource when spring-boot-starter-data-jpa and DB driver are on the classpath; override by providing your own DataSource bean:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@Bean&lt;br&gt;
public DataSource myDataSource() {&lt;br&gt;
    HikariDataSource ds = new HikariDataSource();&lt;br&gt;
    ds.setJdbcUrl("jdbc:postgresql://localhost:5432/demo");&lt;br&gt;
    ds.setUsername("user");&lt;br&gt;
    ds.setPassword("pass");&lt;br&gt;
    return ds;&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can also exclude:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})&lt;br&gt;
public class MyApplication { ... }&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;4. What is the difference between @Component, @Service, @Repository and @Controller?&lt;/strong&gt;&lt;br&gt;
All four are specializations of @Component and tell Spring to manage that class as a bean. @Service marks business logic classes, @Repository marks database access classes and adds exception translation, and @Controller marks web layer classes that handle HTTP requests. Using the right annotation makes your code readable and allows Spring to apply specific behaviour to each layer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. What is Dependency Injection and how does Spring Boot implement it?&lt;/strong&gt;&lt;br&gt;
Dependency Injection means that instead of a class creating its own dependencies, Spring creates and injects them. This makes your code loosely coupled and easier to test. Spring Boot supports three types — constructor injection (recommended), setter injection, and field injection via @Autowired.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;@Service &lt;br&gt;
public class UserService { &lt;br&gt;
private final UserRepository userRepository;&lt;/p&gt;

&lt;p&gt;// Constructor injection — recommended public UserService(UserRepository userRepository) { this.userRepository = userRepository; }&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. What is the difference between @RestController and @Controller?&lt;/strong&gt;&lt;br&gt;
@Controller is used for traditional MVC applications where you return a view (like a JSP page). @RestController combines @Controller and @ResponseBody — it automatically serializes the return value to JSON and writes it directly to the HTTP response. In modern REST API development, you will almost always use @RestController.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@RestController &lt;br&gt;
@RequestMapping("/api/users") &lt;br&gt;
public class UserController { &lt;br&gt;
@GetMapping("/{id}") &lt;br&gt;
public User getUser(@PathVariable Long id) &lt;br&gt;
    { &lt;br&gt;
        return userService.findById(id); &lt;br&gt;
    } &lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. What are Spring Boot Starters?&lt;/strong&gt;&lt;br&gt;
Starters are pre-packaged dependency bundles that simplify your pom.xml. Instead of adding 10 separate dependencies for web development, you add one — spring-boot-starter-web — and Spring Boot brings everything needed. Common starters include spring-boot-starter-data-jpa, spring-boot-starter-security, and spring-boot-starter-test.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. What is application.properties and what is it used for?&lt;/strong&gt;&lt;br&gt;
application.properties is the main configuration file in Spring Boot located in src/main/resources. You use it to configure database connections, server port, logging levels, and any custom properties your application needs. You can also use application.yml as an alternative with cleaner formatting.&lt;/p&gt;

&lt;p&gt;Maven:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;propertiesserver.port=8081 spring.datasource.url=jdbc:postgresql://localhost:5432/mydb spring.datasource.username=postgres spring.datasource.password=secret spring.jpa.hibernate.ddl-auto=update&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;9. What is the difference between @GetMapping, @PostMapping, @PutMapping and @DeleteMapping?&lt;/strong&gt;&lt;br&gt;
These are shortcut annotations for mapping HTTP methods to controller methods. @GetMapping handles GET requests for fetching data, @PostMapping handles POST for creating data, @PutMapping handles PUT for updating, and @DeleteMapping handles DELETE for removing data. They make your REST API code cleaner and more readable than using @RequestMapping with a method parameter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;10. How does Spring Boot connect to a database?&lt;/strong&gt;&lt;br&gt;
Spring Boot connects to a database using the configuration in application.properties. You add the database dependency (like spring-boot-starter-data-jpa), add your database driver (like PostgreSQL or MySQL), and configure the datasource URL, username, and password. Spring Boot auto-configures Hibernate as the JPA provider automatically.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@Entity &lt;br&gt;
@Table(name = "users") &lt;br&gt;
public class User { &lt;br&gt;
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) &lt;br&gt;
private Long id; &lt;br&gt;
private String name; &lt;br&gt;
private String email; &lt;br&gt;
// getters and setters &lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Change server port:&lt;/p&gt;

&lt;p&gt;server.port=9090&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;11. What is JPA and how is it used in Spring Boot?&lt;/strong&gt;&lt;br&gt;
JPA stands for Java Persistence API — it is a specification for mapping Java objects to database tables. Spring Boot uses Hibernate as the default JPA implementation. You annotate your Java class with &lt;a class="mentioned-user" href="https://dev.to/entity"&gt;@entity&lt;/a&gt;, define fields, and Spring Boot handles all the SQL automatically. This means you rarely write raw SQL queries for standard operations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;12. What is a Spring Boot Repository and what is JpaRepository?&lt;/strong&gt;&lt;br&gt;
A Repository is an interface that handles database operations. JpaRepository is the most commonly used — it extends CrudRepository and provides methods like findAll(), findById(), save(), and deleteById() out of the box. You just extend it with your entity type and ID type and Spring Boot creates the implementation automatically.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@Repository &lt;br&gt;
public interface UserRepository extends &lt;br&gt;
JpaRepository&amp;lt;User, Long&amp;gt; { &lt;br&gt;
List findByEmail(String email); &lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;13. What is the difference between @PathVariable and @RequestParam?&lt;/strong&gt;&lt;br&gt;
@PathVariable extracts values from the URL path itself — like /users/42 where 42 is the ID. @RequestParam extracts values from query parameters — like /users?name=Mark. Use @PathVariable for identifying a specific resource and @RequestParam for filtering or optional inputs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;14. What is Spring Security and how do you add it to Spring Boot?&lt;/strong&gt;&lt;br&gt;
Spring Security is a framework for handling authentication and authorization in Spring applications. Adding spring-boot-starter-security to your project automatically secures all endpoints with a default login page. You customize it by extending SecurityFilterChain and defining which endpoints are public and which require authentication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;15. What is JWT and how is it used with Spring Boot?&lt;/strong&gt;&lt;br&gt;
JWT stands for JSON Web Token — a compact, self-contained token used for secure authentication. When a user logs in, your Spring Boot application generates a JWT and sends it to the client. The client sends this token in every subsequent request header. Spring Security validates the token on each request without needing to query the database. java// Adding JWT to Authorization header // Client sends this with every request: // Authorization: Bearer eyJhbGciOiJIUzI1NiJ9...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;16. What is the difference between &lt;a class="mentioned-user" href="https://dev.to/bean"&gt;@bean&lt;/a&gt; and @Component?&lt;/strong&gt;&lt;br&gt;
@Component is used on classes and lets Spring auto-detect them during component scanning. &lt;a class="mentioned-user" href="https://dev.to/bean"&gt;@bean&lt;/a&gt; is used on methods inside a @Configuration class when you need to manually define how a bean is created — useful for third-party classes you cannot annotate directly. Both result in Spring-managed beans but serve different use cases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;17. What is Actuator in Spring Boot?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Spring Boot Actuator provides production-ready monitoring endpoints for your application. After adding spring-boot-starter-actuator, you get endpoints like /actuator/health, /actuator/metrics, and /actuator/info automatically. TCS and Infosys interviewers ask about this because it shows awareness of production concerns beyond just writing code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;18. What is the difference between @RequestBody and @ResponseBody?&lt;/strong&gt;@RequestBody tells Spring to deserialize the incoming HTTP request body (JSON) into a Java object. @ResponseBody tells Spring to serialize the returned Java object into JSON and write it to the HTTP response. When you use @RestController, @ResponseBody is applied automatically to every method.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@PostMapping("/users") &lt;br&gt;
public User createUser(@RequestBody User user) { &lt;br&gt;
return userService.save(user); &lt;br&gt;
}&lt;/code&gt;&lt;br&gt;
Conditional bean based on property:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@Bean&lt;br&gt;
@ConditionalOnProperty(name = "feature.x.enabled", havingValue = "true")&lt;br&gt;
public MyFeature myFeature() { ... }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;19. What is a Microservice and how does Spring Boot support it?&lt;/strong&gt;&lt;br&gt;
A microservice is a small, independently deployable service that does one thing well. Instead of one large application, you build many small ones that communicate via REST APIs or messaging. Spring Boot is ideal for microservices because each service can be its own Spring Boot application — lightweight, independently deployable, and easy to scale.&lt;br&gt;
**&lt;br&gt;
**20. What is @Transactional and when do you use it?&lt;br&gt;
@Transactional ensures that a group of database operations either all succeed or all fail together. If any operation inside the method throws an exception, Spring rolls back all changes automatically. You use it on service methods that perform multiple database operations — like transferring money between accounts.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@Transactional &lt;br&gt;
public void transferMoney(Long fromId, Long toId, Double amount) { &lt;br&gt;
accountRepository.debit(fromId, amount); accountRepository.credit(toId, amount); // If credit fails, debit is also rolled back &lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;21. What is the difference between SOAP and REST?&lt;/strong&gt;&lt;br&gt;
REST is lightweight, uses HTTP methods (GET, POST, PUT, DELETE), and typically exchanges JSON. SOAP is a protocol with strict standards, uses XML, and is more complex. Modern applications including TCS and Infosys projects use REST almost exclusively. SOAP is still found in legacy banking and government systems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;22. What is Spring Boot DevTools?&lt;/strong&gt;&lt;br&gt;
DevTools is a dependency that improves developer experience by automatically restarting your application when code changes are detected. It also enables live reload in browsers and disables template caching during development. You add spring-boot-devtools to your project and it only activates in development — never in production.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;23. What is the difference between findById() and getById() in JPA?&lt;/strong&gt;&lt;br&gt;
findById() returns an Optional — you must handle the case where the entity might not exist. getById() returns the entity directly but throws EntityNotFoundException if not found. Always prefer findById() in modern Spring Boot applications as it forces you to handle the missing case explicitly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;24. What is Lombok and why is it used in Spring Boot projects?&lt;/strong&gt;&lt;br&gt;
Lombok is a library that generates boilerplate code like getters, setters, constructors, and toString methods automatically using annotations. Instead of writing 50 lines of getters and setters, you add &lt;a class="mentioned-user" href="https://dev.to/data"&gt;@data&lt;/a&gt; to your class and Lombok generates everything at compile time. It makes your entity and DTO classes much cleaner. java@Data&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@Data &lt;br&gt;
@Entity &lt;br&gt;
public class User { &lt;br&gt;
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) &lt;br&gt;
private Long id; &lt;br&gt;
private String name; &lt;br&gt;
private String email; // No getters/setters needed — Lombok generates them &lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;25. What is an Exception Handler in Spring Boot?&lt;/strong&gt;&lt;br&gt;
@ExceptionHandler lets you handle specific exceptions in a controller. @ControllerAdvice combined with @ExceptionHandler creates a global exception handler that catches exceptions across all controllers. This gives you one central place to return consistent error responses instead of scattering try-catch blocks everywhere.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@ControllerAdvice &lt;br&gt;
public class GlobalExceptionHandler { @ExceptionHandler(ResourceNotFoundException.class) &lt;br&gt;
public ResponseEntity handleNotFound(ResourceNotFoundException ex) { &lt;br&gt;
return ResponseEntity.status(404).body(ex.getMessage()); &lt;br&gt;
} &lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;26. What is the difference between PUT and PATCH?&lt;/strong&gt;&lt;br&gt;
PUT replaces the entire resource — you send the complete object with all fields. PATCH updates only the fields you send — useful when you want to change just one field without sending the entire object. In practice, most Indian IT company interviews expect you to know this difference for REST API design questions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;27. What is the use of @Value annotation?&lt;/strong&gt;&lt;br&gt;
@Value injects values from application.properties directly into your class fields. Instead of hardcoding configuration values in your code, you define them in properties files and inject them where needed. This makes your application configurable without changing code.&lt;/p&gt;

&lt;p&gt;Simple Javafile:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@Service &lt;br&gt;
public class EmailService { &lt;br&gt;
@Value("${app.email.sender}") &lt;br&gt;
private String senderEmail; &lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;28. What are common performance tuning tips for Spring Boot apps?&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
    Use connection pooling (HikariCP defaults).&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Tune JVM/Garbage Collector settings for production.

Enable caching (Spring Cache) for expensive operations.

Use async processing or reactive model where appropriate.

Limit component scanning scope and enable lazy initialization if startup time matters.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Enable lazy init:&lt;/p&gt;

&lt;p&gt;spring.main.lazy-initialization=true&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;29. What is the difference between Spring Boot and Spring MVC?&lt;/strong&gt;&lt;br&gt;
Key changes:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Spring MVC is a web framework within Spring for building web applications following the Model-View-Controller pattern. Spring Boot is a tool that makes setting up Spring MVC (and any other Spring module) faster by providing auto-configuration and embedded servers. You almost always use both together — Spring Boot sets everything up and Spring MVC handles the web layer.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;30. What is an Embedded Server in Spring Boot?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Spring Boot comes with an embedded Tomcat server by default — meaning you don't need to install or configure an external server. You just run your application as a plain Java program and the server starts automatically on port 8080. This makes deployment simple — you package everything into one JAR file and run it anywhere Java is installed.&lt;/p&gt;

&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;You now have a compact, practice-ready collection of the top Spring Boot interview questions and answers. More than memorizing each response, focus on understanding the core concepts—how auto-configuration works, why starters exist, how DI and Spring Data simplify persistence, and how Actuator, security, and testing make applications production-ready. Interviewers care more about clear thinking and practical experience than perfectly recited definitions.&lt;/p&gt;

&lt;p&gt;Quick next steps&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Build a small CRUD service from scratch (use Spring Initializr) and add JPA, security, and Actuator.

Write unit and integration tests (use @SpringBootTest and relevant test slices).

Practice explaining trade-offs: when to use @ConfigurationProperties vs @Value, or monolith vs microservice.

Review a couple of real interview questions aloud to get comfortable with concise, structured answers.

Read the official Spring guides for any gaps and keep a sample repository you can demo.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Keep it simple, practice by building, and explain your thought process clearly during interviews. Good luck — you’ve got this!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>productivity</category>
      <category>springboot</category>
    </item>
  </channel>
</rss>
