Skip to main content

TCS Java Interview | Java | Spring Boot | Microservices | Database


This post is based on a Java backend developer interview simulation and provides direct transcript-based answers to help you prepare for similar interviews.

📺 This interview scenario was inspired by a video from the YouTube channel: CloudTech.
🔗 Watch the full video here: https://www.youtube.com/watch?v=yVj2EgwZxk4


1. Can you introduce yourself and talk about your tech stack and domains?

I have around 4.5 years of experience working as a Java developer. My core expertise is in Java and developing REST APIs using Spring Boot. I also have basic knowledge of microservices architecture. On the database side, I work with SQL and Oracle. Additionally, I have exposure to UI technologies like Angular, HTML, and CSS, but they are secondary skills. My primary focus is backend Java development.


2. Which version of Java are you currently working on?

We are currently using Java 8 but are in the process of upgrading to Java 17.


3. How would you rate yourself in Core Java out of 5?

I would rate myself a 4 out of 5 in Core Java.


4. What are the different ways to create threads in Java?

Threads can be created in three ways:

  • By extending the Thread class and overriding the run() method.

  • By implementing the Runnable interface and providing the implementation for run().

  • By using the Executor framework which manages a pool of threads.


5. What is the recommended way to create threads?

  • For multiple threads: use the Executor framework.

  • For a single thread and if the class is not extending any other class: extend Thread.

  • In general, it's best to implement Runnable.


6. What is a deadlock and how can we avoid it?

Deadlock occurs when two or more threads are waiting on each other’s resources. For example, Thread 1 holds Resource A and waits for Resource B, while Thread 2 holds Resource B and waits for Resource A.
To avoid deadlock:

  • Use locks in a consistent order.

  • Use tryLock() from java.util.concurrent.locks.

  • Minimize synchronized blocks.


7. What are the thread states in Java?

  • New: Thread is created but not started.

  • Runnable: Thread is ready to run.

  • Blocked/Waiting/Timed Waiting: Thread is waiting to acquire a lock or a specific time.

  • Terminated: Thread has finished execution.


8. Can a terminated thread be restarted?

No, once a thread is terminated, it cannot be restarted. You can only create a new thread.


9. Difference between throw and throws?

  • throw is used to explicitly throw an exception in the code.

  • throws is used in the method signature to indicate it may throw exceptions.


10. Types of exceptions in Java?

  • Checked exceptions: Checked at compile-time (e.g., IOException).

  • Unchecked exceptions: Runtime exceptions (e.g., NullPointerException, ArrayIndexOutOfBoundsException).


11. What is try-with-resources?

A try-with-resources block allows us to declare resources like BufferedReader with the try block. The resource is automatically closed after execution. The resource must implement AutoCloseable.


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

  • == compares object references.

  • .equals() compares the content of objects.

Example:

String s1 = "abc";
String s2 = new String("abc");
s1 == s2 // false
s1.equals(s2) // true

13. Difference between abstract class and interface?

  • Abstract class can have both abstract and concrete methods.

  • Interface can have abstract methods, and from Java 8 onwards, also static and default methods.

  • A class can extend only one abstract class but can implement multiple interfaces.


14. What is Dependency Injection and how does Spring Boot support it?

Dependency Injection is a design pattern where dependencies are injected rather than created. Spring Boot supports it using annotations like @Autowired or @Bean.


15. What is circular dependency and how does Spring handle it?

Spring handles circular dependencies using proxy objects or by using @Lazy annotation to lazily load dependencies. Best practice is to refactor code to avoid circular dependencies.


16. Difference between CrudRepository and JpaRepository?

  • CrudRepository: Basic CRUD operations.

  • JpaRepository: Extends CrudRepository and provides extra features like pagination and sorting.


17. What kind of repository do you use in your project?

We use JpaRepository because it supports pagination and other features.


18. Best practices to improve Spring Boot performance?

  • Use caching to avoid frequent DB calls.

  • Apply proper indexing in DB.

  • Use Spring Boot Actuator for monitoring.

  • Use @Async for asynchronous processing.


19. How to convert a monolithic application to microservices?

  • Analyze and identify domain boundaries.

  • Break the application into independent services.

  • Use REST for synchronous communication, and Kafka/RabbitMQ for asynchronous.

  • Add API Gateway.

  • Use Service Discovery.

  • Apply CI/CD with Docker and Kubernetes.

  • Implement unit and regression testing.


20. Difference between synchronous and asynchronous communication in microservices?

  • Synchronous: Client sends request and waits (e.g., REST APIs).

  • Asynchronous: Client sends message and continues (e.g., Kafka, RabbitMQ).


21. Java 8 Program: Unique Words from Sentence

public class Client {
    public static void main(String[] args) {
        String str = "Java is fun and Java is powerful";
        List<String> uniqueWords = Arrays.stream(str.split(" "))
            .map(String::toLowerCase)
            .distinct()
            .sorted()
            .collect(Collectors.toList());
        System.out.println(uniqueWords);
    }
}

Output: [and, fun, is, java, powerful]


📌 Conclusion

👉 If you found this useful, explore our other posts on:

  • Java Interview Questions

  • Spring Boot Real-World Scenarios

  • Microservices Implementation Guide

💬 Got any questions or tips to share? Drop them in the comments!

Comments

Popular posts from this blog

Top 20 Spring Boot Microservices Architecture Interview Questions (With Speakable Answers)

Top 20 Spring Boot Microservices Architecture Interview Questions (With Speakable Answers) * * * 1. What is Microservices Architecture?   → Microservices architecture breaks an application into small, independent services. Each one handles a specific business function and can be developed, deployed, and scaled independently. They usually communicate over REST APIs or messaging queues. * * * 2. How does Spring Boot help in building microservices?   → Spring Boot offers embedded servers, auto-configuration, starter templates, and production-ready tools. It works well with Spring Cloud to provide service discovery, config management, load balancing, and more. * * * 3. What are the core components in a microservices setup?   → Key components include:   ✓ API Gateway   ✓ Eureka (Service Discovery)   ✓ Config Server   ✓ Kafka or RabbitMQ   ✓ Circuit Breaker (like Resilience4j)   ✓ Centralized logging and monitoring (ELK, Prometheus) * * * 4. What i...

Top 15 React Interview Questions for 1–2 Years Experience

🟦 Top 15 React Interview Questions for 1–2 Years Experience Preparing for a React interview with 1–2 years of experience? Here's a carefully curated list of 15 important React questions with clear, real-world answers. These are frequently asked in interviews at companies like TCS, Infosys, Cognizant, Capgemini, and product-based firms. Q1. What is the Virtual DOM in React, and how does it improve performance? Answer: The Virtual DOM is a lightweight, in-memory copy of the real DOM. When state/props change, React creates a new Virtual DOM tree, compares it with the old one (diffing), and only updates the parts of the real DOM that changed. This makes rendering much faster and improves performance in large applications. Q2. What is JSX in React? Answer: JSX stands for JavaScript XML. It allows us to write HTML elements in JavaScript and place them in the DOM without using createElement() . JSX improves code readability and is transpiled to React.createElement() calls. ...

Top 15 Spring Boot Interview Questions and Answers – Real Examples (2025)

Top 15 Spring Boot Interview Questions – 2025 Spring Boot is one of the most demanded frameworks for Java backend development. Whether you're interviewing for TCS, Infosys, or a product-based company, these Spring Boot questions will help you prepare like a pro. Here are 15 questions with detailed explanations for developers with 1–2 years of experience. Q1. What is Spring Boot? Answer: Spring Boot is a Java-based open-source framework built on top of the Spring Framework. It helps developers create stand-alone, production-ready Spring applications with minimal configuration. Its key features include: Auto-configuration Embedded servers (Tomcat, Jetty) Starter dependencies Production-ready tools (Actuator, Metrics, etc.) Example: You can create a REST API within minutes by using @RestController and spring-boot-starter-web — no need for external web server deployment. Q2. What is the role of @SpringBootApplication annotation? Answer: This annotation i...