TCS Java Interview Preparation: Core Concepts, Collections, Exceptions & Multithreading

Prepare for TCS Java interviews with 15 important Java interview questions covering OOP, exception handling, strings, collections, multithreading, and coding problems, with detailed answers and follow-up questions.

TCS Java interview questions and answers

Preparing for a TCS Java interview requires more than memorizing definitions. Interviewers can start with a basic Java concept and then move into a practical example, ask you to compare two concepts, or introduce a follow-up problem based on your answer.

This becomes especially important when Java is listed as one of your primary technical skills. 

The interviewer may ask about object-oriented programming, exception handling, strings, collections, multithreading, or programming fundamentals and then connect those concepts to a project mentioned on your resume. 

The source material also highlights that interviewers can build deeper questions from the technologies and projects candidates mention.

This TCS Java interview preparation guide covers 15 important Java interview questions, with detailed explanations, code examples, and answers to the follow-up questions an interviewer may ask next.

TCS Java Interview Topics You Should Prepare

For a broader preparation plan covering the exam pattern, strategy, and selection process, see this TCS NQT preparation guide 2026.

Before practicing TCS Java interview questions, divide your preparation into the areas that are most relevant to your resume.

Your core preparation should include:

The source material specifically identifies programming fundamentals, strings, collections, multithreading, and memory concepts as areas candidates should revise when Java appears on their resume.

If you prefer Java, the Great Learning Data Structures and Algorithms in Java course can help you build core data structures and algorithm skills while practicing problem-solving in Java. 

Free Course

Learn Data Structures and Algorithms in Java

Master the basics of data structures, algorithms, recursion, and time complexity in Java. Ideal for beginners. Learn and earn a certificate.

1.8L+ Learners
4.48
Inscríbete Gratis Ahora

A useful sequence is:

Fundamentals → Core Java → Coding → Project Application → Follow-Up Questions

Along with technical preparation, candidates can also practice TCS aptitude questions and answers to strengthen the aptitude skills required for TCS-related assessments.

For every topic, ask:

What is it? → Why is it used? → How does it work? → Where can it be used?

TCS Java OOP Interview Questions and Answers

1. What Is Encapsulation in Java?

Answer:
Encapsulation means keeping data and the methods that operate on that data together inside a class while controlling how that data is accessed.

Consider a bank account:

java
public class BankAccount {
    private double balance;

    public void deposit(double amount) {
        if (amount > 0) {
            balance += amount;
        }
    }

    public double getBalance() {
        return balance;
    }

    public static void main(String[] args) {
        BankAccount account = new BankAccount();
        account.deposit(5000);
        System.out.println("Balance: " + account.getBalance());
    }
}

Here, balance is private, so other classes cannot directly change it. They must use methods such as deposit().

This prevents invalid updates and keeps the rules for changing the data inside the class.

Follow-up: How does encapsulation improve maintainability and security?

Answer:
Encapsulation improves maintainability because changes to the internal implementation can be made without forcing other parts of the application to change. It also improves control over data because access can be restricted and validated through methods.

For example, a deposit() method can reject negative values before modifying the account balance.

2. What Is Inheritance in Java?

Answer:
Inheritance allows one class to acquire properties and methods from another class. It is useful when there is a genuine relationship between the classes and common behavior can be reused.

java
class Employee {
    void showRole() {
        System.out.println("Employee");
    }
}

class Developer extends Employee {
    void writeCode() {
        System.out.println("Writing code");
    }

    public static void main(String[] args) {
        Developer developer = new Developer();
        developer.showRole();
        developer.writeCode();
    }
}

Developer inherits showRole() from Employee while adding its own writeCode() method.

Inheritance can reduce code duplication, but it should represent a meaningful relationship between classes rather than being used only for code reuse.

Follow-up: What are the different types of inheritance, and which forms does Java support directly with classes?

Answer:
Common inheritance forms are single, multilevel, hierarchical, multiple, and hybrid inheritance.

Java directly supports single, multilevel, and hierarchical inheritance with classes. Java does not support multiple inheritance of classes because a class cannot extend more than one class. Multiple-inheritance-like behavior can instead be achieved through interfaces.

3. What Is Polymorphism in Java?

Answer:
Polymorphism allows the same method or interface-level operation to produce different behaviour depending on the context or object.

Method overloading is one example:

java
class Printer {
    void print(String text) {
        System.out.println(text);
    }

    void print(int number) {
        System.out.println(number);
    }

    public static void main(String[] args) {
        Printer printer = new Printer();
        printer.print("Hello");
        printer.print(100);
    }
}

The method name is the same, but the parameter list is different.

Method overriding is another form:

java
class Animal {
    void sound() {
        System.out.println("Animal sound");
    }
}

class Dog extends Animal {
    @Override
    void sound() {
        System.out.println("Bark");
    }

    public static void main(String[] args) {
        Animal animal = new Dog();
        animal.sound();
    }
}

The Dog class provides its own implementation of the inherited method.

Follow-up: What is runtime polymorphism?

Answer:
Runtime polymorphism occurs when the method that executes is determined at runtime based on the actual object rather than the reference type.

java
Animal animal = new Dog();
animal.sound();

Although the reference type is Animal, the actual object is Dog, so the overridden Dog.sound() method executes.

This is commonly associated with method overriding and dynamic method dispatch.

Continue Reading: Difference Between Abstract Class and Interface in Java

4. What Is the Difference Between Abstraction and Encapsulation?

Answer:
Abstraction focuses on exposing the essential behaviour while hiding unnecessary implementation details.

Encapsulation focuses on controlling access to an object's internal state and keeping the data and related methods together.

For example:

java
class Car {
    public void start() {
        checkFuel();
        checkBattery();
        startEngine();
    }

    private void checkFuel() {
        // internal logic
    }

    private void checkBattery() {
        // internal logic
    }

    private void startEngine() {
        // internal logic
    }

    public static void main(String[] args) {
        Car car = new Car();
        car.start();
        System.out.println("Car started successfully");
    }
}

The user only needs to call start(). The internal steps remain hidden.

Follow-up: How can interfaces be used to achieve abstraction in Java?

Answer:
An interface can define the operations a class must provide without exposing how those operations are implemented.

java
interface Payment {
    void pay(double amount);
}

class CardPayment implements Payment {
    public void pay(double amount) {
        System.out.println("Paid using card");
    }

    public static void main(String[] args) {
        Payment payment = new CardPayment();
        payment.pay(1000);
    }
}

The caller can work with the Payment interface without depending on the implementation details of CardPayment.

TCS Java Exception Handling Interview Questions

5. What Is Exception Handling in Java?

Answer:
Exception handling provides a structured way to manage runtime problems.

Java uses try, catch, finally, throw, and throws for exception handling.

java
public class DivisionExample {
    public static void main(String[] args) {
        try {
            int result = 10 / 0;
            System.out.println(result);
        } catch (ArithmeticException e) {
            System.out.println("Cannot divide by zero");
        }
    }
}

The risky operation is placed inside try, and the corresponding error is handled by catch.

Follow-up: What is the difference between checked and unchecked exceptions?

Answer:
Checked exceptions are exceptions that the compiler requires the program to handle or declare. Unchecked exceptions are generally subclasses of RuntimeException and are not subject to that compile-time requirement.

The distinction matters because checked exceptions commonly represent conditions that a program may reasonably anticipate and handle, while unchecked exceptions often indicate programming or runtime problems.

6. What Is the Difference Between throw and throws?

Answer:
throw explicitly throws an exception at a particular point in the program.

java
public class ValidateAge {
    static void validateAge(int age) {
        if (age < 18) {
            throw new IllegalArgumentException("Invalid age");
        }
        System.out.println("Valid age");
    }

    public static void main(String[] args) {
        try {
            validateAge(20);
            validateAge(16);
        } catch (IllegalArgumentException e) {
            System.out.println(e.getMessage());
        }
    }
}

throws appears in a method declaration and indicates that the method may pass an exception to its caller.

java
public class ReadDataExample {
    static void readData() throws Exception {
        // processing
    }

    public static void main(String[] args) {
        try {
            readData();
            System.out.println("Data processed successfully");
        } catch (Exception e) {
            System.out.println("An error occurred: " + e.getMessage());
        }
    }
}

Follow-up: When would you handle an exception inside a method instead of passing it to the caller?

Answer:
Handle an exception inside the method when the method has enough information to recover from the problem or provide an appropriate response.

Pass it to the caller when the higher layer is better positioned to decide what should happen.

For example, a lower-level data-access method may pass a database-related exception upward so that the application service layer can decide whether to retry, log, or return an appropriate response.

TCS Java Strings and Collections Interview Questions

7. What Is the Difference Between == and equals() in Java?

Answer:
For primitive values, == compares values. For objects, == compares references. The equals() method is intended to compare logical equality when the class provides an appropriate implementation.

java
public class StringComparison {
    public static void main(String[] args) {
        String first = new String("TCS");
        String second = new String("TCS");
        System.out.println(first == second);
        System.out.println(first.equals(second));
    }
}

The two objects contain the same text but are separate objects, so reference comparison and content comparison can produce different results.

Follow-up: Why should hashCode() also be overridden when equals() is overridden?

Answer:
Hash-based collections such as HashMap and HashSet use hashCode() to determine where an object belongs and use equality checks to distinguish matching objects.

If two objects are considered equal by equals(), they should return the same hash code. Otherwise, logically equal objects may end up in different hash locations and hash-based collections may behave incorrectly.

The rule is:

Equal objects → Same hash code

The reverse is not required:

Same hash code ≠ Necessarily equal objects

8. How Would You Choose Between Different Java Collections?

Answer:
Choose a collection based on the operations your application needs most frequently.

Ask:

Do I need duplicates? → Do I need ordered elements? → Do I need key-based lookup? → How often will elements be inserted or removed?

For example:

java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class CollectionExample {
    public static void main(String[] args) {
        List<String> names = new ArrayList<>();
        names.add("Amit");
        names.add("Priya");

        Set<String> uniqueNames = new HashSet<>();
        uniqueNames.add("Amit");
        uniqueNames.add("Amit");

        Map<Integer, String> employees = new HashMap<>();
        employees.put(101, "Amit");

        System.out.println("Names: " + names);
        System.out.println("Unique Names: " + uniqueNames);
        System.out.println("Employees: " + employees);
    }
}

A List is useful for a sequence, a Set for uniqueness, and a Map for key-value relationships.

Follow-up: Which collection would you choose when fast key-based lookup is required?

Answer:
A HashMap is a common choice when fast average-case key-based lookup is required.

java
import java.util.HashMap;
import java.util.Map;

public class EmployeeMap {
    public static void main(String[] args) {
        Map<Integer, String> employees = new HashMap<>();
        employees.put(101, "Amit");
        System.out.println(employees.get(101));
    }
}

The key is used to locate the corresponding value efficiently.

The final choice should still depend on the requirements, such as ordering, uniqueness, concurrency, or predictable iteration behaviour.

9. How Would You Reverse a String Without Using a Built-In Reverse Operation?

Answer:
One simple approach is to traverse the string from the last character to the first.

java
class ReverseString {
    static String reverse(String text) {
        StringBuilder result = new StringBuilder();
        for (int i = text.length() - 1; i >= 0; i--) {
            result.append(text.charAt(i));
        }
        return result.toString();
    }

    public static void main(String[] args) {
        System.out.println(reverse("TCS"));
    }
}

For "TCS", the output is:

output
SCT

This demonstrates loops, strings, indexing, and string construction.

Follow-up: Can you reverse a string in place?

Answer:
A Java String is immutable, so it cannot be directly modified in place. If the interview requires an in-place style operation, convert the characters into a mutable structure such as a character array.

java
public class ReverseArray {
    public static void main(String[] args) {
        char[] chars = "TCS".toCharArray();
        int left = 0;
        int right = chars.length - 1;

        while (left < right) {
            char temp = chars[left];
            chars[left] = chars[right];
            chars[right] = temp;
            left++;
            right--;
        }

        System.out.println(new String(chars));
    }
}

This uses two pointers and swaps characters from the two ends.

TCS Java Multithreading and Memory Questions

10. What Is Multithreading in Java?

Answer:
Multithreading allows multiple threads to execute within the same process.

java
class Task extends Thread {
    @Override
    public void run() {
        System.out.println("Task is running");
    }
}

public class Main {
    public static void main(String[] args) {
        Task task = new Task();
        task.start();
    }
}

The start() method begins the thread's execution.

Multithreading can help applications perform multiple tasks concurrently, but shared resources introduce additional problems.

Follow-up: What problems can occur when multiple threads access shared data?

Answer:
Multiple threads accessing shared data can cause race conditions, inconsistent results, and visibility-related problems.

For example, if two threads simultaneously update a shared counter, both may read the same old value and overwrite each other's updates.

This is why shared mutable data often requires appropriate concurrency control.

11. What Is the Difference Between a Process and a Thread?

Answer:
A process is an independent program in execution with its own memory space. A thread is an execution unit within a process, and multiple threads within the same process can share resources.

Processes provide stronger isolation, while threads are useful for concurrent work within the same application.

Follow-up: What can happen if two threads modify the same shared variable simultaneously?

Answer:
The result may become unpredictable because the operations may interleave.

For example:

count++;

is not necessarily one indivisible operation. If two threads read the same value before either writes its update, one increment may effectively overwrite the other.

This can produce a final value smaller than expected.

12. What Is a Race Condition?

Answer:
A race condition occurs when multiple threads access shared data and the final result depends on the order in which their operations execute.

Consider:

java
class Counter {
    int count = 0;

    void increment() {
        count++;
    }

    public static void main(String[] args) {
        Counter counter = new Counter();
        counter.increment();
        counter.increment();
        System.out.println("Count: " + counter.count);
    }
}

If two threads call increment() simultaneously, both may read the same value before either update is stored.

One way to protect the operation is synchronization:

java
class Counter {
    private int count = 0;

    synchronized void increment() {
        count++;
    }

    int getCount() {
        return count;
    }

    public static void main(String[] args) {
        Counter counter = new Counter();
        counter.increment();
        counter.increment();
        System.out.println("Count: " + counter.getCount());
    }
}

Follow-up: What are the disadvantages of excessive synchronization?

Answer:
Excessive synchronization can reduce concurrency because threads may spend more time waiting for locks.

It can also increase the risk of deadlocks when multiple locks are acquired in an unsafe order.

Therefore, synchronization should protect the specific shared operation that requires coordination rather than unnecessarily blocking large portions of an application.

TCS Java Coding Interview Questions

13. How Would You Find the Largest and Second-Largest Elements in an Array?

Answer:
If only the largest element is required, a single traversal is enough. For the second-largest element, maintain both the largest and second-largest values while traversing the array.

java
class SecondLargest {
    static int find(int[] numbers) {
        int largest = Integer.MIN_VALUE;
        int secondLargest = Integer.MIN_VALUE;

        for (int number : numbers) {
            if (number > largest) {
                secondLargest = largest;
                largest = number;
            } else if (number > secondLargest && number != largest) {
                secondLargest = number;
            }
        }

        return secondLargest;
    }

    public static void main(String[] args) {
        int[] numbers = {10, 5, 20, 8, 15};
        System.out.println("Second largest: " + find(numbers));
    }
}

This avoids sorting the complete array.

The time complexity is O(n) because every element is examined once.

Follow-up: How would you handle an array where all elements are equal?

Answer:
You need to define what “second-largest” means.

If the question asks for the second distinct-largest value, an array such as:

[5, 5, 5, 5]

has no valid second-largest distinct value.

The implementation should therefore explicitly handle that case rather than returning an incorrect value.

This is an important interview habit: clarify assumptions before coding.

14. How Would You Reverse a Linked List?

Answer:
An iterative solution uses three references:

Previous → Current → Next

java
class Node {
    int data;
    Node next;

    Node(int data) {
        this.data = data;
    }
}

class ReverseList {
    static Node reverse(Node head) {
        Node previous = null;
        Node current = head;

        while (current != null) {
            Node next = current.next;
            current.next = previous;
            previous = current;
            current = next;
        }

        return previous;
    }

    public static void main(String[] args) {
        Node head = new Node(1);
        head.next = new Node(2);
        head.next.next = new Node(3);

        Node reversed = reverse(head);

        while (reversed != null) {
            System.out.print(reversed.data + " ");
            reversed = reversed.next;
        }
    }
}

The important step is storing current.next before changing the current node's link.

Otherwise, the remaining part of the list could become inaccessible.

Follow-up: Can you reverse a linked list recursively?

Answer:
Yes. A recursive solution moves toward the last node and then changes the direction of the links while returning from the recursive calls.

java
class Node {
    int data;
    Node next;

    Node(int data) {
        this.data = data;
    }
}

public class ReverseList {
    static Node reverse(Node head) {
        if (head == null || head.next == null) {
            return head;
        }

        Node newHead = reverse(head.next);
        head.next.next = head;
        head.next = null;

        return newHead;
    }

    public static void main(String[] args) {
        Node head = new Node(1);
        head.next = new Node(2);
        head.next.next = new Node(3);

        Node reversed = reverse(head);

        while (reversed != null) {
            System.out.print(reversed.data + " ");
            reversed = reversed.next;
        }
    }
}

The base case handles an empty list or a single-node list. The recursive call reaches the end, and the links are reversed during the return phase.

Possible follow-up:
What is the space complexity of the recursive approach?

Answer:
The recursive version uses O(n) call-stack space in the worst case, while the iterative version uses O(1) additional space.

15. How Would You Find the First Non-Repeating Character in a String?

Answer:
A practical approach is to count the frequency of each character and then perform a second pass to find the first character whose count is one.

java
import java.util.HashMap;
import java.util.Map;

class FirstNonRepeating {
    static char find(String text) {
        Map<Character, Integer> frequency = new HashMap<>();

        for (char ch : text.toCharArray()) {
            frequency.put(ch, frequency.getOrDefault(ch, 0) + 1);
        }

        for (char ch : text.toCharArray()) {
            if (frequency.get(ch) == 1) {
                return ch;
            }
        }

        return '\0';
    }

    public static void main(String[] args) {
        String text = "swiss";
        System.out.println("First non-repeating character: " + find(text));
    }
}

The first loop builds the frequency map, while the second loop preserves the original order and identifies the first non-repeating character.

This problem combines strings, collections, iteration, and problem-solving, making it useful for a Java coding discussion.

Follow-up: Can you solve this using a frequency array instead of a HashMap?

Answer:
Yes, when the input is restricted to a known character set, a frequency array can replace the hash map.

For example, for lowercase English letters:

java
class FrequencyArray {
    static char find(String text) {
        int[] frequency = new int[26];

        for (char ch : text.toCharArray()) {
            frequency[ch - 'a']++;
        }

        for (char ch : text.toCharArray()) {
            if (frequency[ch - 'a'] == 1) {
                return ch;
            }
        }

        return '\0';
    }

    public static void main(String[] args) {
        String text = "swiss";
        System.out.println("First non-repeating character: " + find(text));
    }
}

This approach can use constant-sized auxiliary storage because the array always contains 26 positions for lowercase English letters.

If the input can contain a wider or unknown character set, a HashMap may be more appropriate.

Final Thoughts

TCS Java interview preparation should combine technical understanding, coding ability, and clear communication. Knowing a definition is useful, but being able to demonstrate it with code and explain the reasoning behind your implementation is more valuable.

If you are also preparing for the broader TCS NQT coding round, explore these TCS NQT coding questions and answers to practice additional programming problems.

Focus your preparation on:

Core Java → OOP → Exception Handling → Strings & Collections → Multithreading → Coding → Project Application

For every question, practice answering the follow-up before moving to another topic. An interviewer may ask why you chose an approach, what happens under a different input, or whether your solution can be improved.

Your goal should be to move comfortably from:

“What is it?” → “How does it work?” → “Why would you use it?” → “Can you implement it?” → “What happens in this case?”

That is the level of preparation that turns Java knowledge into interview-ready technical understanding.

Frequently Asked Questions

1. What Java topics should I prepare for a TCS interview?
Prepare programming fundamentals, OOP, exception handling, strings, collections, multithreading, memory concepts, and coding problems relevant to your resume and target role.

2. What Java questions are commonly asked in TCS interviews?
Questions can cover encapsulation, inheritance, polymorphism, abstraction, exception handling, == vs. equals(), collections, multithreading, process vs. thread, and programming problems involving arrays, strings, and linked lists.

3. Does TCS ask Java coding questions?
Coding or problem-solving questions may be included when Java is relevant to the role. Prepare to explain the approach, implementation, complexity, and edge cases rather than focusing only on the final output.

4. How important are Java OOP concepts in a TCS interview?
OOP concepts such as encapsulation, inheritance, polymorphism, and abstraction form an important part of core Java preparation and can lead to practical follow-up questions.

5. How should I prepare for Java exception handling questions?
Understand try, catch, finally, throw, and throws, and practice explaining when an exception should be handled locally and when it should be passed to another layer.

6. How should I prepare for Java collections questions?
Understand the purpose of common collections and practice choosing a suitable collection based on requirements such as ordering, uniqueness, and key-based lookup.

7. How can I prepare for Java multithreading questions?
Understand processes, threads, shared data, race conditions, and synchronization. Practice explaining both the benefits of concurrent execution and the problems that can occur when threads share mutable data.

8. Should I memorize TCS Java interview answers?
No. Understand the concept, practice a code example, and prepare for “why,” “how,” and “what if” follow-ups. This makes it easier to answer questions even when the interviewer changes the wording.

Avatar photo
Great Learning Editorial Team
The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.

Go Beyond Learning. Get Job-Ready.

Build in-demand skills for today's jobs with free expert-led courses and practical AI tools.

Explore All Courses
Scroll to Top