{"id":119697,"date":"2026-09-21T15:18:03","date_gmt":"2026-09-21T09:48:03","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/tcs-java-interview-questions\/"},"modified":"2026-09-21T15:18:05","modified_gmt":"2026-09-21T09:48:05","slug":"tcs-java-interview-questions","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/tcs-java-interview-questions\/","title":{"rendered":"TCS Java Interview Preparation: Core Concepts, Collections, Exceptions &#038; Multithreading"},"content":{"rendered":"\n<p>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.<\/p>\n\n\n\n<p>This becomes especially important when Java is listed as one of your primary technical skills.&nbsp;<\/p>\n\n\n\n<p>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.&nbsp;<\/p>\n\n\n\n<p>The source material also highlights that interviewers can build deeper questions from the technologies and projects candidates mention.<\/p>\n\n\n\n<p>This TCS Java interview preparation guide covers <strong>15 important Java interview questions<\/strong>, with detailed explanations, code examples, and answers to the follow-up questions an interviewer may ask next.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"tcs-java-interview-topics-you-should-prepare\"><strong>TCS Java Interview Topics You Should Prepare<\/strong><\/h2>\n\n\n\n<p>For a broader preparation plan covering the exam pattern, strategy, and selection process, see this <a href=\"https:\/\/www.mygreatlearning.com\/blog\/tcs-nqt-preparation-guide-2026\/\">TCS NQT preparation guide 2026<\/a>.<\/p>\n\n\n\n<p>Before practicing TCS Java interview questions, divide your preparation into the areas that are most relevant to your resume.<\/p>\n\n\n\n<p>Your core preparation should include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Java programming fundamentals<\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-java\/\">Object-oriented programming<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/exception-handling-in-java\/\">Exception handling<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/strings-in-java\/\">Strings<\/a> and <a href=\"https:\/\/www.mygreatlearning.com\/blog\/java-array-length\/\">arrays<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/collection-in-java\/\">Collections<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/multithreading-in-java\/\">Multithreading<\/a><\/li>\n\n\n\n<li>Basic memory concepts<\/li>\n\n\n\n<li>Java-related project questions<\/li>\n<\/ul>\n\n\n\n<p>The source material specifically identifies programming fundamentals, strings, collections, multithreading, and memory concepts as areas candidates should revise when Java appears on their resume.<\/p>\n\n\n\n<p>If you prefer Java, the <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/data-structures-and-algorithms-in-java?utm_source=blog\">Great Learning Data Structures and Algorithms in Java course<\/a> can help you build core data structures and algorithm skills while practicing problem-solving in Java.&nbsp;<\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Free Course<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/data-structures-and-algorithms-in-java\" class=\"courses-cta-title-link\">Learn Data Structures and Algorithms in Java<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Master the basics of data structures, algorithms, recursion, and time complexity in Java. Ideal for beginners. Learn and earn a certificate.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>1.8L+ Learners<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>4.48<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/data-structures-and-algorithms-in-java\" class=\"courses-cta-button\">\n                Inscr\u00edbete Gratis Ahora\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<p><strong>A useful sequence is:<\/strong><\/p>\n\n\n\n<p><strong>Fundamentals \u2192 Core Java \u2192 Coding \u2192 Project Application \u2192 Follow-Up Questions<\/strong><\/p>\n\n\n\n<p>Along with technical preparation, candidates can also practice <a href=\"https:\/\/www.mygreatlearning.com\/blog\/tcs-aptitude-questions-answers\/\">TCS aptitude questions and answers<\/a> to strengthen the aptitude skills required for TCS-related assessments.<\/p>\n\n\n\n<p>For every topic, ask:<\/p>\n\n\n\n<p><strong>What is it? \u2192 Why is it used? \u2192 How does it work? \u2192 Where can it be used?<\/strong><\/p>\n\n\n\n<p><strong>TCS Java OOP Interview Questions and Answers<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1-what-is-encapsulation-in-java\"><strong>1. What Is Encapsulation in Java?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong><a href=\"https:\/\/www.mygreatlearning.com\/blog\/abstract-class-and-encapsulation-in-java\">Encapsulation<\/a> means keeping data and the methods that operate on that data together inside a class while controlling how that data is accessed.<\/p>\n\n\n\n<p><strong>Consider a bank account:<\/strong><\/p>\n\n\n\n<div id=\"copy-6ab120526fe71\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>public class BankAccount {\n    private double balance;\n\n    public void deposit(double amount) {\n        if (amount &gt; 0) {\n            balance += amount;\n        }\n    }\n\n    public double getBalance() {\n        return balance;\n    }\n\n    public static void main(String[] args) {\n        BankAccount account = new BankAccount();\n        account.deposit(5000);\n        System.out.println(&quot;Balance: &quot; + account.getBalance());\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>Here, balance is private, so other classes cannot directly change it. They must use methods such as deposit().<\/p>\n\n\n\n<p>This prevents invalid updates and keeps the rules for changing the data inside the class.<\/p>\n\n\n\n<p><strong>Follow-up: How does encapsulation improve maintainability and security?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>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.<\/p>\n\n\n\n<p>For example, a deposit() method can reject negative values before modifying the account balance.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2-what-is-inheritance-in-java\"><strong>2. What Is Inheritance in Java?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong><a href=\"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-java\">Inheritance<\/a> 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.<\/p>\n\n\n\n<div id=\"copy-6ab120526fe8d\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>class Employee {\n    void showRole() {\n        System.out.println(&quot;Employee&quot;);\n    }\n}\n\nclass Developer extends Employee {\n    void writeCode() {\n        System.out.println(&quot;Writing code&quot;);\n    }\n\n    public static void main(String[] args) {\n        Developer developer = new Developer();\n        developer.showRole();\n        developer.writeCode();\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>Developer inherits showRole() from Employee while adding its own writeCode() method.<\/p>\n\n\n\n<p>Inheritance can reduce code duplication, but it should represent a meaningful relationship between classes rather than being used only for code reuse.<\/p>\n\n\n\n<p><strong>Follow-up: What are the different types of inheritance, and which forms does Java support directly with classes?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>Common inheritance forms are single, multilevel, hierarchical, multiple, and hybrid inheritance.<\/p>\n\n\n\n<p>Java directly supports <strong>single, multilevel, and hierarchical inheritance with classes<\/strong>. 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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3-what-is-polymorphism-in-java\"><strong>3. What Is Polymorphism in Java?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong><a href=\"https:\/\/www.mygreatlearning.com\/blog\/polymorphism-in-java\">Polymorphism<\/a> allows the same method or interface-level operation to produce different behaviour depending on the context or object.<\/p>\n\n\n\n<p>Method overloading is one example:<\/p>\n\n\n\n<div id=\"copy-6ab120526fea2\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>class Printer {\n    void print(String text) {\n        System.out.println(text);\n    }\n\n    void print(int number) {\n        System.out.println(number);\n    }\n\n    public static void main(String[] args) {\n        Printer printer = new Printer();\n        printer.print(&quot;Hello&quot;);\n        printer.print(100);\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>The method name is the same, but the parameter list is different.<\/p>\n\n\n\n<p>Method overriding is another form:<\/p>\n\n\n\n<div id=\"copy-6ab120526feb4\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>class Animal {\n    void sound() {\n        System.out.println(&quot;Animal sound&quot;);\n    }\n}\n\nclass Dog extends Animal {\n    @Override\n    void sound() {\n        System.out.println(&quot;Bark&quot;);\n    }\n\n    public static void main(String[] args) {\n        Animal animal = new Dog();\n        animal.sound();\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>The Dog class provides its own implementation of the inherited method.<\/p>\n\n\n\n<p><strong>Follow-up: What is runtime polymorphism?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>Runtime polymorphism occurs when the method that executes is determined at runtime based on the actual object rather than the reference type.<\/p>\n\n\n\n<div id=\"copy-6ab120526feb9\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>Animal animal = new Dog();\nanimal.sound();<\/code><\/pre><\/div>\n\n\n\n<p>Although the reference type is Animal, the actual object is Dog, so the overridden Dog.sound() method executes.<\/p>\n\n\n\n<p>This is commonly associated with <strong>method overriding and dynamic method dispatch<\/strong>.<\/p>\n\n\n\n<p>Continue Reading: <a href=\"https:\/\/www.mygreatlearning.com\/blog\/abstract-class-vs-interface-in-java\">Difference Between Abstract Class and Interface in Java<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"4-what-is-the-difference-between-abstraction-and-encapsulation\"><strong>4. What Is the Difference Between Abstraction and Encapsulation?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>Abstraction focuses on exposing the essential behaviour while hiding unnecessary implementation details.<\/p>\n\n\n\n<p>Encapsulation focuses on controlling access to an object's internal state and keeping the data and related methods together.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<div id=\"copy-6ab120526fecb\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>class Car {\n    public void start() {\n        checkFuel();\n        checkBattery();\n        startEngine();\n    }\n\n    private void checkFuel() {\n        \/\/ internal logic\n    }\n\n    private void checkBattery() {\n        \/\/ internal logic\n    }\n\n    private void startEngine() {\n        \/\/ internal logic\n    }\n\n    public static void main(String[] args) {\n        Car car = new Car();\n        car.start();\n        System.out.println(&quot;Car started successfully&quot;);\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>The user only needs to call start(). The internal steps remain hidden.<\/p>\n\n\n\n<p><strong>Follow-up: How can interfaces be used to achieve abstraction in Java?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<br><\/strong>An interface can define the operations a class must provide without exposing how those operations are implemented.<\/p>\n\n\n\n<div id=\"copy-6ab120526fedc\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>interface Payment {\n    void pay(double amount);\n}\n\nclass CardPayment implements Payment {\n    public void pay(double amount) {\n        System.out.println(&quot;Paid using card&quot;);\n    }\n\n    public static void main(String[] args) {\n        Payment payment = new CardPayment();\n        payment.pay(1000);\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>The caller can work with the Payment interface without depending on the implementation details of CardPayment.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"tcs-java-exception-handling-interview-questions\"><strong>TCS Java Exception Handling Interview Questions<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"5-what-is-exception-handling-in-java\"><strong>5. What Is Exception Handling in Java?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>Exception handling provides a structured way to manage runtime problems.<\/p>\n\n\n\n<p>Java uses try, catch, finally, throw, and throws for exception handling.<\/p>\n\n\n\n<div id=\"copy-6ab120526feeb\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>public class DivisionExample {\n    public static void main(String[] args) {\n        try {\n            int result = 10 \/ 0;\n            System.out.println(result);\n        } catch (ArithmeticException e) {\n            System.out.println(&quot;Cannot divide by zero&quot;);\n        }\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>The risky operation is placed inside try, and the corresponding error is handled by catch.<\/p>\n\n\n\n<p><strong>Follow-up: What is the difference between checked and unchecked exceptions?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>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.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"6-what-is-the-difference-between-throw-and-throws\"><strong>6. What Is the Difference Between <\/strong><strong>throw<\/strong><strong> and <\/strong><strong>throws<\/strong><strong>?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>throw explicitly throws an exception at a particular point in the program.<\/p>\n\n\n\n<div id=\"copy-6ab120526feff\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>public class ValidateAge {\n    static void validateAge(int age) {\n        if (age &lt; 18) {\n            throw new IllegalArgumentException(&quot;Invalid age&quot;);\n        }\n        System.out.println(&quot;Valid age&quot;);\n    }\n\n    public static void main(String[] args) {\n        try {\n            validateAge(20);\n            validateAge(16);\n        } catch (IllegalArgumentException e) {\n            System.out.println(e.getMessage());\n        }\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>throws appears in a method declaration and indicates that the method may pass an exception to its caller.<\/p>\n\n\n\n<div id=\"copy-6ab120526ff10\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>public class ReadDataExample {\n    static void readData() throws Exception {\n        \/\/ processing\n    }\n\n    public static void main(String[] args) {\n        try {\n            readData();\n            System.out.println(&quot;Data processed successfully&quot;);\n        } catch (Exception e) {\n            System.out.println(&quot;An error occurred: &quot; + e.getMessage());\n        }\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p><strong>Follow-up: When would you handle an exception inside a method instead of passing it to the caller?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>Handle an exception inside the method when the method has enough information to recover from the problem or provide an appropriate response.<\/p>\n\n\n\n<p>Pass it to the caller when the higher layer is better positioned to decide what should happen.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"tcs-java-strings-and-collections-interview-questions\"><strong>TCS Java Strings and Collections Interview Questions<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"7-what-is-the-difference-between-and-equals-in-java\"><strong>7. What Is the Difference Between <\/strong><strong>==<\/strong><strong> and <\/strong><strong>equals()<\/strong><strong> in Java?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>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.<\/p>\n\n\n\n<div id=\"copy-6ab120526ff1f\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>public class StringComparison {\n    public static void main(String[] args) {\n        String first = new String(&quot;TCS&quot;);\n        String second = new String(&quot;TCS&quot;);\n        System.out.println(first == second);\n        System.out.println(first.equals(second));\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>The two objects contain the same text but are separate objects, so reference comparison and content comparison can produce different results.<\/p>\n\n\n\n<p><strong>Follow-up: Why should <\/strong><strong>hashCode()<\/strong><strong> also be overridden when <\/strong><strong>equals()<\/strong><strong> is overridden?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>Hash-based collections such as <a href=\"https:\/\/www.mygreatlearning.com\/blog\/hashmap-in-java\">HashMap<\/a> and <a href=\"https:\/\/www.mygreatlearning.com\/blog\/hashset-in-java\">HashSet<\/a> use hashCode() to determine where an object belongs and use equality checks to distinguish matching objects.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p><strong>The rule is:<\/strong><\/p>\n\n\n\n<p><strong>Equal objects \u2192 Same hash code<\/strong><\/p>\n\n\n\n<p>The reverse is not required:<\/p>\n\n\n\n<p><strong>Same hash code \u2260 Necessarily equal objects<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"8-how-would-you-choose-between-different-java-collections\"><strong>8. How Would You Choose Between Different Java Collections?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>Choose a collection based on the operations your application needs most frequently.<\/p>\n\n\n\n<p><strong>Ask:<\/strong><\/p>\n\n\n\n<p><strong>Do I need duplicates? \u2192 Do I need ordered elements? \u2192 Do I need key-based lookup? \u2192 How often will elements be inserted or removed?<\/strong><\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<div id=\"copy-6ab120526ff3a\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>import java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Set;\n\npublic class CollectionExample {\n    public static void main(String[] args) {\n        List&lt;String&gt; names = new ArrayList&lt;&gt;();\n        names.add(&quot;Amit&quot;);\n        names.add(&quot;Priya&quot;);\n\n        Set&lt;String&gt; uniqueNames = new HashSet&lt;&gt;();\n        uniqueNames.add(&quot;Amit&quot;);\n        uniqueNames.add(&quot;Amit&quot;);\n\n        Map&lt;Integer, String&gt; employees = new HashMap&lt;&gt;();\n        employees.put(101, &quot;Amit&quot;);\n\n        System.out.println(&quot;Names: &quot; + names);\n        System.out.println(&quot;Unique Names: &quot; + uniqueNames);\n        System.out.println(&quot;Employees: &quot; + employees);\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>A List is useful for a sequence, a Set for uniqueness, and a Map for key-value relationships.<\/p>\n\n\n\n<p><strong>Follow-up: Which collection would you choose when fast key-based lookup is required?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>A HashMap is a common choice when fast average-case key-based lookup is required.<\/p>\n\n\n\n<div id=\"copy-6ab120526ff4c\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>import java.util.HashMap;\nimport java.util.Map;\n\npublic class EmployeeMap {\n    public static void main(String[] args) {\n        Map&lt;Integer, String&gt; employees = new HashMap&lt;&gt;();\n        employees.put(101, &quot;Amit&quot;);\n        System.out.println(employees.get(101));\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>The key is used to locate the corresponding value efficiently.<\/p>\n\n\n\n<p>The final choice should still depend on the requirements, such as ordering, uniqueness, concurrency, or predictable iteration behaviour.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"9-how-would-you-reverse-a-string-without-using-a-built-in-reverse-operation\"><strong>9. How Would You Reverse a String Without Using a Built-In Reverse Operation?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>One simple approach is to traverse the string from the last character to the first.<\/p>\n\n\n\n<div id=\"copy-6ab120526ff5e\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>class ReverseString {\n    static String reverse(String text) {\n        StringBuilder result = new StringBuilder();\n        for (int i = text.length() - 1; i &gt;= 0; i--) {\n            result.append(text.charAt(i));\n        }\n        return result.toString();\n    }\n\n    public static void main(String[] args) {\n        System.out.println(reverse(&quot;TCS&quot;));\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>For \"TCS\", the output is:<\/p>\n\n\n\n<div id=\"copy-6ab120526ff63\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">output<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>SCT<\/code><\/pre><\/div>\n\n\n\n<p>This demonstrates loops, strings, indexing, and string construction.<\/p>\n\n\n\n<p><strong>Follow-up: Can you reverse a string in place?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>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.<\/p>\n\n\n\n<div id=\"copy-6ab120526ff77\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>public class ReverseArray {\n    public static void main(String[] args) {\n        char[] chars = &quot;TCS&quot;.toCharArray();\n        int left = 0;\n        int right = chars.length - 1;\n\n        while (left &lt; right) {\n            char temp = chars[left];\n            chars[left] = chars[right];\n            chars[right] = temp;\n            left++;\n            right--;\n        }\n\n        System.out.println(new String(chars));\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>This uses two pointers and swaps characters from the two ends.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"tcs-java-multithreading-and-memory-questions\"><strong>TCS Java Multithreading and Memory Questions<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"10-what-is-multithreading-in-java\"><strong>10. What Is Multithreading in Java?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong><a href=\"https:\/\/www.mygreatlearning.com\/blog\/multithreading-in-java\/\">Multithreading<\/a> allows multiple threads to execute within the same process.<\/p>\n\n\n\n<div id=\"copy-6ab120526ff87\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>class Task extends Thread {\n    @Override\n    public void run() {\n        System.out.println(&quot;Task is running&quot;);\n    }\n}\n\npublic class Main {\n    public static void main(String[] args) {\n        Task task = new Task();\n        task.start();\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>The start() method begins the thread's execution.<\/p>\n\n\n\n<p>Multithreading can help applications perform multiple tasks concurrently, but shared resources introduce additional problems.<\/p>\n\n\n\n<p><strong>Follow-up: What problems can occur when multiple threads access shared data?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>Multiple threads accessing shared data can cause race conditions, inconsistent results, and visibility-related problems.<\/p>\n\n\n\n<p>For example, if two threads simultaneously update a shared counter, both may read the same old value and overwrite each other's updates.<\/p>\n\n\n\n<p>This is why shared mutable data often requires appropriate concurrency control.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"11-what-is-the-difference-between-a-process-and-a-thread\"><strong>11. What Is the Difference Between a Process and a Thread?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>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.<\/p>\n\n\n\n<p>Processes provide stronger isolation, while threads are useful for concurrent work within the same application.<\/p>\n\n\n\n<p><strong>Follow-up: What can happen if two threads modify the same shared variable simultaneously?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>The result may become unpredictable because the operations may interleave.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>count++;<\/p>\n<\/blockquote>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>This can produce a final value smaller than expected.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"12-what-is-a-race-condition\"><strong>12. What Is a Race Condition?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>A race condition occurs when multiple threads access shared data and the final result depends on the order in which their operations execute.<\/p>\n\n\n\n<p>Consider:<\/p>\n\n\n\n<div id=\"copy-6ab120526ff97\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>class Counter {\n    int count = 0;\n\n    void increment() {\n        count++;\n    }\n\n    public static void main(String[] args) {\n        Counter counter = new Counter();\n        counter.increment();\n        counter.increment();\n        System.out.println(&quot;Count: &quot; + counter.count);\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>If two threads call increment() simultaneously, both may read the same value before either update is stored.<\/p>\n\n\n\n<p>One way to protect the operation is synchronization:<\/p>\n\n\n\n<div id=\"copy-6ab120526ffa8\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>class Counter {\n    private int count = 0;\n\n    synchronized void increment() {\n        count++;\n    }\n\n    int getCount() {\n        return count;\n    }\n\n    public static void main(String[] args) {\n        Counter counter = new Counter();\n        counter.increment();\n        counter.increment();\n        System.out.println(&quot;Count: &quot; + counter.getCount());\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p><strong>Follow-up: What are the disadvantages of excessive synchronization?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>Excessive synchronization can reduce concurrency because threads may spend more time waiting for locks.<\/p>\n\n\n\n<p>It can also increase the risk of deadlocks when multiple locks are acquired in an unsafe order.<\/p>\n\n\n\n<p>Therefore, synchronization should protect the specific shared operation that requires coordination rather than unnecessarily blocking large portions of an application.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"tcs-java-coding-interview-questions\"><strong>TCS Java Coding Interview Questions<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"13-how-would-you-find-the-largest-and-second-largest-elements-in-an-array\"><strong>13. How Would You Find the Largest and Second-Largest Elements in an Array?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>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.<\/p>\n\n\n\n<div id=\"copy-6ab120526ffbf\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>class SecondLargest {\n    static int find(int[] numbers) {\n        int largest = Integer.MIN_VALUE;\n        int secondLargest = Integer.MIN_VALUE;\n\n        for (int number : numbers) {\n            if (number &gt; largest) {\n                secondLargest = largest;\n                largest = number;\n            } else if (number &gt; secondLargest &amp;&amp; number != largest) {\n                secondLargest = number;\n            }\n        }\n\n        return secondLargest;\n    }\n\n    public static void main(String[] args) {\n        int[] numbers = {10, 5, 20, 8, 15};\n        System.out.println(&quot;Second largest: &quot; + find(numbers));\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>This avoids sorting the complete array.<\/p>\n\n\n\n<p>The time complexity is <strong>O(n)<\/strong> because every element is examined once.<\/p>\n\n\n\n<p><strong>Follow-up: How would you handle an array where all elements are equal?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>You need to define what \u201csecond-largest\u201d means.<\/p>\n\n\n\n<p>If the question asks for the <strong>second distinct-largest value<\/strong>, an array such as:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>[5, 5, 5, 5]<\/p>\n<\/blockquote>\n\n\n\n<p>has no valid second-largest distinct value.<\/p>\n\n\n\n<p>The implementation should therefore explicitly handle that case rather than returning an incorrect value.<\/p>\n\n\n\n<p>This is an important interview habit: clarify assumptions before coding.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"14-how-would-you-reverse-a-linked-list\"><strong>14. How Would You Reverse a Linked List?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>An iterative solution uses three references:<\/p>\n\n\n\n<p><strong>Previous \u2192 Current \u2192 Next<\/strong><\/p>\n\n\n\n<div id=\"copy-6ab120526ffd4\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>class Node {\n    int data;\n    Node next;\n\n    Node(int data) {\n        this.data = data;\n    }\n}\n\nclass ReverseList {\n    static Node reverse(Node head) {\n        Node previous = null;\n        Node current = head;\n\n        while (current != null) {\n            Node next = current.next;\n            current.next = previous;\n            previous = current;\n            current = next;\n        }\n\n        return previous;\n    }\n\n    public static void main(String[] args) {\n        Node head = new Node(1);\n        head.next = new Node(2);\n        head.next.next = new Node(3);\n\n        Node reversed = reverse(head);\n\n        while (reversed != null) {\n            System.out.print(reversed.data + &quot; &quot;);\n            reversed = reversed.next;\n        }\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>The important step is storing current.next before changing the current node's link.<\/p>\n\n\n\n<p>Otherwise, the remaining part of the list could become inaccessible.<\/p>\n\n\n\n<p><strong>Follow-up: Can you reverse a linked list recursively?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>Yes. A recursive solution moves toward the last node and then changes the direction of the links while returning from the recursive calls.<\/p>\n\n\n\n<div id=\"copy-6ab120526ffe8\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>class Node {\n    int data;\n    Node next;\n\n    Node(int data) {\n        this.data = data;\n    }\n}\n\npublic class ReverseList {\n    static Node reverse(Node head) {\n        if (head == null || head.next == null) {\n            return head;\n        }\n\n        Node newHead = reverse(head.next);\n        head.next.next = head;\n        head.next = null;\n\n        return newHead;\n    }\n\n    public static void main(String[] args) {\n        Node head = new Node(1);\n        head.next = new Node(2);\n        head.next.next = new Node(3);\n\n        Node reversed = reverse(head);\n\n        while (reversed != null) {\n            System.out.print(reversed.data + &quot; &quot;);\n            reversed = reversed.next;\n        }\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>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.<\/p>\n\n\n\n<p><strong>Possible follow-up:<\/strong><strong><br><\/strong>What is the space complexity of the recursive approach?<\/p>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>The recursive version uses <strong>O(n)<\/strong> call-stack space in the worst case, while the iterative version uses <strong>O(1)<\/strong> additional space.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"15-how-would-you-find-the-first-non-repeating-character-in-a-string\"><strong>15. How Would You Find the First Non-Repeating Character in a String?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>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.<\/p>\n\n\n\n<div id=\"copy-6ab120526fffe\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>import java.util.HashMap;\nimport java.util.Map;\n\nclass FirstNonRepeating {\n    static char find(String text) {\n        Map&lt;Character, Integer&gt; frequency = new HashMap&lt;&gt;();\n\n        for (char ch : text.toCharArray()) {\n            frequency.put(ch, frequency.getOrDefault(ch, 0) + 1);\n        }\n\n        for (char ch : text.toCharArray()) {\n            if (frequency.get(ch) == 1) {\n                return ch;\n            }\n        }\n\n        return &#039;\\0&#039;;\n    }\n\n    public static void main(String[] args) {\n        String text = &quot;swiss&quot;;\n        System.out.println(&quot;First non-repeating character: &quot; + find(text));\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>The first loop builds the frequency map, while the second loop preserves the original order and identifies the first non-repeating character.<\/p>\n\n\n\n<p>This problem combines <strong>strings, collections, iteration, and problem-solving<\/strong>, making it useful for a Java coding discussion.<\/p>\n\n\n\n<p><strong>Follow-up: Can you solve this using a frequency array instead of a <\/strong><strong>HashMap<\/strong><strong>?<\/strong><\/p>\n\n\n\n<p><strong>Answer:<\/strong><strong><br><\/strong>Yes, when the input is restricted to a known character set, a frequency array can replace the hash map.<\/p>\n\n\n\n<p>For example, for lowercase English letters:<\/p>\n\n\n\n<div id=\"copy-6ab1205270011\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">java<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>class FrequencyArray {\n    static char find(String text) {\n        int[] frequency = new int[26];\n\n        for (char ch : text.toCharArray()) {\n            frequency[ch - &#039;a&#039;]++;\n        }\n\n        for (char ch : text.toCharArray()) {\n            if (frequency[ch - &#039;a&#039;] == 1) {\n                return ch;\n            }\n        }\n\n        return &#039;\\0&#039;;\n    }\n\n    public static void main(String[] args) {\n        String text = &quot;swiss&quot;;\n        System.out.println(&quot;First non-repeating character: &quot; + find(text));\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>This approach can use constant-sized auxiliary storage because the array always contains 26 positions for lowercase English letters.<\/p>\n\n\n\n<p>If the input can contain a wider or unknown character set, a HashMap may be more appropriate.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"final-thoughts\"><strong>Final Thoughts<\/strong><\/h2>\n\n\n\n<p>TCS Java interview preparation should combine <strong>technical understanding, coding ability, and clear communication<\/strong>. Knowing a definition is useful, but being able to demonstrate it with code and explain the reasoning behind your implementation is more valuable.<\/p>\n\n\n\n<p>If you are also preparing for the broader TCS NQT coding round, explore these <a href=\"https:\/\/www.mygreatlearning.com\/blog\/tcs-nqt-coding-questions-answers\/\">TCS NQT coding questions and answers<\/a> to practice additional programming problems.<\/p>\n\n\n\n<p>Focus your preparation on:<\/p>\n\n\n\n<p><strong>Core Java \u2192 OOP \u2192 Exception Handling \u2192 Strings &amp; Collections \u2192 Multithreading \u2192 Coding \u2192 Project Application<\/strong><\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Your goal should be to move comfortably from:<\/p>\n\n\n\n<p><strong>\u201cWhat is it?\u201d \u2192 \u201cHow does it work?\u201d \u2192 \u201cWhy would you use it?\u201d \u2192 \u201cCan you implement it?\u201d \u2192 \u201cWhat happens in this case?\u201d<\/strong><\/p>\n\n\n\n<p>That is the level of preparation that turns Java knowledge into interview-ready technical understanding.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"frequently-asked-questions\"><strong>Frequently Asked Questions<\/strong><\/h2>\n\n\n\n<p><strong>1. What Java topics should I prepare for a TCS interview?<\/strong><strong><br><\/strong>Prepare programming fundamentals, OOP, exception handling, strings, collections, multithreading, memory concepts, and coding problems relevant to your resume and target role.<\/p>\n\n\n\n<p><strong>2. What Java questions are commonly asked in TCS interviews?<\/strong><strong><br><\/strong>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.<\/p>\n\n\n\n<p><strong>3. Does TCS ask Java coding questions?<\/strong><strong><br><\/strong>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.<\/p>\n\n\n\n<p><strong>4. How important are Java OOP concepts in a TCS interview?<\/strong><strong><br><\/strong>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.<\/p>\n\n\n\n<p><strong>5. How should I prepare for Java exception handling questions?<\/strong><strong><br><\/strong>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.<\/p>\n\n\n\n<p><strong>6. How should I prepare for Java collections questions?<\/strong><strong><br><\/strong>Understand the purpose of common collections and practice choosing a suitable collection based on requirements such as ordering, uniqueness, and key-based lookup.<\/p>\n\n\n\n<p><strong>7. How can I prepare for Java multithreading questions?<\/strong><strong><br><\/strong>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.<\/p>\n\n\n\n<p><strong>8. Should I memorize TCS Java interview answers?<\/strong><strong><br><\/strong>No. Understand the concept, practice a code example, and prepare for \u201cwhy,\u201d \u201chow,\u201d and \u201cwhat if\u201d follow-ups. This makes it easier to answer questions even when the interviewer changes the wording.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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.<\/p>\n","protected":false},"author":41,"featured_media":119698,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[17946,25860],"tags":[36974],"content_type":[],"class_list":["post-119697","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-career","category-software","tag-tcs-java-interview-preperation"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>TCS Java Interview Questions: 15 Technical Questions &amp; Answers<\/title>\n<meta name=\"description\" content=\"Prepare for TCS Java interviews with 15 important questions and answers covering OOP, exceptions, strings, collections, multithreading, and coding.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/tcs-java-interview-questions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"TCS Java Interview Preparation: Core Concepts, Collections, Exceptions &amp; Multithreading\" \/>\n<meta property=\"og:description\" content=\"Prepare for TCS Java interviews with 15 important questions and answers covering OOP, exceptions, strings, collections, multithreading, and coding.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/tcs-java-interview-questions\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-21T09:48:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-09-21T09:48:05+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2026\/09\/image-26.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1734\" \/>\n\t<meta property=\"og:image:height\" content=\"907\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"15 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-java-interview-questions\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-java-interview-questions\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"TCS Java Interview Preparation: Core Concepts, Collections, Exceptions &#038; Multithreading\",\"datePublished\":\"2026-09-21T09:48:03+00:00\",\"dateModified\":\"2026-09-21T09:48:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-java-interview-questions\\\/\"},\"wordCount\":3696,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-java-interview-questions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/image-26.png\",\"keywords\":[\"TCS java interview preperation\"],\"articleSection\":[\"Career Development\",\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-java-interview-questions\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-java-interview-questions\\\/\",\"name\":\"TCS Java Interview Questions: 15 Technical Questions & Answers\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-java-interview-questions\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-java-interview-questions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/image-26.png\",\"datePublished\":\"2026-09-21T09:48:03+00:00\",\"dateModified\":\"2026-09-21T09:48:05+00:00\",\"description\":\"Prepare for TCS Java interviews with 15 important questions and answers covering OOP, exceptions, strings, collections, multithreading, and coding.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-java-interview-questions\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-java-interview-questions\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-java-interview-questions\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/image-26.png\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/image-26.png\",\"width\":1734,\"height\":907,\"caption\":\"Prepare for TCS Java interviews with 15 important questions covering OOP, exception handling, strings, collections, multithreading, and coding.\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-java-interview-questions\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"TCS Java Interview Preparation: Core Concepts, Collections, Exceptions &#038; Multithreading\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"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.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"TCS Java Interview Questions: 15 Technical Questions & Answers","description":"Prepare for TCS Java interviews with 15 important questions and answers covering OOP, exceptions, strings, collections, multithreading, and coding.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/tcs-java-interview-questions\/","og_locale":"en_US","og_type":"article","og_title":"TCS Java Interview Preparation: Core Concepts, Collections, Exceptions & Multithreading","og_description":"Prepare for TCS Java interviews with 15 important questions and answers covering OOP, exceptions, strings, collections, multithreading, and coding.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/tcs-java-interview-questions\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2026-09-21T09:48:03+00:00","article_modified_time":"2026-09-21T09:48:05+00:00","og_image":[{"width":1734,"height":907,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2026\/09\/image-26.png","type":"image\/png"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"15 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/tcs-java-interview-questions\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/tcs-java-interview-questions\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"TCS Java Interview Preparation: Core Concepts, Collections, Exceptions &#038; Multithreading","datePublished":"2026-09-21T09:48:03+00:00","dateModified":"2026-09-21T09:48:05+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/tcs-java-interview-questions\/"},"wordCount":3696,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/tcs-java-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2026\/09\/image-26.png","keywords":["TCS java interview preperation"],"articleSection":["Career Development","IT\/Software Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/tcs-java-interview-questions\/","url":"https:\/\/www.mygreatlearning.com\/blog\/tcs-java-interview-questions\/","name":"TCS Java Interview Questions: 15 Technical Questions & Answers","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/tcs-java-interview-questions\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/tcs-java-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2026\/09\/image-26.png","datePublished":"2026-09-21T09:48:03+00:00","dateModified":"2026-09-21T09:48:05+00:00","description":"Prepare for TCS Java interviews with 15 important questions and answers covering OOP, exceptions, strings, collections, multithreading, and coding.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/tcs-java-interview-questions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/tcs-java-interview-questions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/tcs-java-interview-questions\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2026\/09\/image-26.png","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2026\/09\/image-26.png","width":1734,"height":907,"caption":"Prepare for TCS Java interviews with 15 important questions covering OOP, exception handling, strings, collections, multithreading, and coding."},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/tcs-java-interview-questions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"TCS Java Interview Preparation: Core Concepts, Collections, Exceptions &#038; Multithreading"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"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.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2026\/09\/image-26.png",1734,907,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2026\/09\/image-26-150x150.png",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2026\/09\/image-26-300x157.png",300,157,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2026\/09\/image-26-768x402.png",768,402,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2026\/09\/image-26-1024x536.png",1024,536,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2026\/09\/image-26-1536x803.png",1536,803,true],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2026\/09\/image-26.png",1734,907,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2026\/09\/image-26-640x853.png",640,853,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2026\/09\/image-26-96x96.png",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2026\/09\/image-26-150x78.png",150,78,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"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.","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/119697","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=119697"}],"version-history":[{"count":4,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/119697\/revisions"}],"predecessor-version":[{"id":119703,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/119697\/revisions\/119703"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/119698"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=119697"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=119697"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=119697"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=119697"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}