Add office photos
TCS logo
Engaged Employer

TCS

Verified
3.7
based on 89.7k Reviews
Video summary
Filter interviews by
Clear (1)

100+ TCS Java Developer Interview Questions and Answers

Updated 19 Feb 2025

Q1. what are the difference between abstract class and interface, and throw and throws, and why we use throws?? Why String is Immutable?

Ans.

Explaining differences between abstract class and interface, throw and throws, and why we use throws. Also, why String is immutable.

  • Abstract class can have both abstract and non-abstract methods, while interface can only have abstract methods.

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

  • Throw is used to explicitly throw an exception, while throws is used to declare the exceptions that a method may throw.

  • We use throws to inform the caller o...read more

View 5 more answers
right arrow

Q2. What are the main OOPS concepts in java and explain one by one?

Ans.

Java OOPS concepts include inheritance, polymorphism, encapsulation, and abstraction.

  • Inheritance allows a class to inherit properties and methods from another class.

  • Polymorphism allows objects to take on multiple forms and behave differently based on their context.

  • Encapsulation hides the implementation details of a class and only exposes necessary information.

  • Abstraction allows for the creation of abstract classes and interfaces that can be implemented by other classes.

  • Exampl...read more

View 13 more answers
right arrow
TCS Java Developer Interview Questions and Answers for Freshers
illustration image

Q3. 1. What is JDK, JVM, JRE.

Ans.

JDK is a development kit, JRE is a runtime environment, and JVM is a virtual machine for executing Java code.

  • JDK includes JRE and development tools like javac and java

  • JRE includes JVM and necessary libraries to run Java applications

  • JVM is responsible for interpreting Java bytecode and executing it

  • Example: JDK 8 includes JRE 8 and development tools like javac and java

  • Example: JRE 8 includes JVM 8 and necessary libraries to run Java applications

View 13 more answers
right arrow

Q4. What is the use of private variables even though they are accessible via getters and setters from some other class?

Ans.

Private variables provide encapsulation and data hiding.

  • Private variables can only be accessed within the class they are declared in, providing encapsulation and preventing direct modification from outside the class.

  • Getters and setters provide controlled access to private variables, allowing for validation and manipulation of the data before it is accessed or modified.

  • For example, a class may have a private variable for a person's age, but the getter can return a calculated a...read more

Add your answer
right arrow
Discover TCS interview dos and don'ts from real experiences

Q5. Where I implemented Executor service in my project?

Ans.

Implemented Executor service in the backend for parallel processing.

  • Implemented ExecutorService in the backend to handle multiple requests concurrently.

  • Used ExecutorService to execute multiple tasks in parallel.

  • Implemented ExecutorService to improve the performance of the application.

  • Used ExecutorService to manage thread pools and execute tasks asynchronously.

Add your answer
right arrow

Q6. What is the difference between Hashmap and Hashtable?

Ans.

Hashtable is synchronized and does not allow null keys or values, while HashMap is not synchronized and allows null keys and values.

  • Hashtable is thread-safe, while HashMap is not.

  • Hashtable does not allow null keys or values, while HashMap allows null keys and values.

  • Hashtable is slower than HashMap due to synchronization.

  • Hashtable is a legacy class, while HashMap is part of the Java Collections Framework.

  • Hashtable is recommended to be used in multi-threaded environments, whil...read more

View 1 answer
right arrow
Are these interview questions helpful?

Q7. What is daemon thread? How it help in multithreading?

Ans.

Daemon thread is a low priority thread that runs in the background and provides services to other threads.

  • Daemon threads are used for tasks that don't require user interaction or input.

  • They are automatically terminated when all non-daemon threads have completed.

  • Examples include garbage collection, logging, and monitoring.

  • They can be created using setDaemon() method.

  • Daemon threads should not be used for tasks that require data consistency or integrity.

  • They can help in improvin...read more

View 1 answer
right arrow

Q8. What is Exception and what is Exception Handling in java ?

Ans.

Exception is an event that occurs during the execution of a program and disrupts the normal flow of instructions.

  • Exception is a subclass of Throwable class.

  • Exception Handling is a mechanism to handle runtime errors and prevent program termination.

  • try-catch block is used to handle exceptions.

  • Multiple catch blocks can be used to handle different types of exceptions.

  • finally block is used to execute code after try-catch block.

  • Example: int a = 10/0; will throw ArithmeticException....read more

View 2 more answers
right arrow
Share interview questions and help millions of jobseekers 🌟
man with laptop

Q9. how to use synchronization in java

Ans.

Synchronization in Java is used to control access to shared resources by multiple threads.

  • Synchronization can be achieved using synchronized keyword or locks.

  • It ensures that only one thread can access the shared resource at a time.

  • Synchronization can be applied to methods or blocks of code.

  • Example: synchronized void method() { //code }

  • Example: synchronized(obj) { //code }

View 2 more answers
right arrow

Q10. Stream API how to use over the collection

Ans.

Stream API is used to perform operations on collections in a functional programming style.

  • Stream API provides a set of methods to perform operations on collections such as filtering, mapping, and reducing.

  • It allows for concise and readable code by using lambda expressions.

  • Stream API supports parallel processing for improved performance.

  • Examples: stream.filter(x -> x > 5), stream.map(x -> x * 2), stream.reduce(0, (x, y) -> x + y)

View 1 answer
right arrow

Q11. What is core features of spring framework?

Ans.

Spring framework has core features like dependency injection, aspect-oriented programming, and Spring MVC.

  • Dependency Injection: allows objects to be created and managed by Spring container

  • Aspect-Oriented Programming: provides modularization of cross-cutting concerns

  • Spring MVC: provides a model-view-controller architecture for web applications

Add your answer
right arrow

Q12. What is singleton class in java?

Ans.

Singleton class is a class that can have only one instance at a time.

  • It is used to provide a global point of access to the instance.

  • It is implemented by making the constructor private and providing a static method to get the instance.

  • Example: java.lang.Runtime, java.awt.Desktop, java.util.Calendar

  • It can be thread-safe by using synchronized keyword or using enum.

View 4 more answers
right arrow

Q13. Can we override start() method ?

Ans.

Yes, we can override start() method in Java.

  • The start() method is defined in the Thread class and is responsible for starting a new thread of execution.

  • We can override the start() method to provide our own implementation of thread execution.

  • However, it is recommended to avoid overriding the start() method and instead use the run() method for custom thread execution.

  • Example: public void start() { // custom implementation }

View 1 answer
right arrow

Q14. Real-time example of opps in current project

Ans.

In my current project, I implemented object-oriented programming (OOPs) principles to design and develop a banking application.

  • Used encapsulation to protect sensitive customer data

  • Implemented inheritance to create different types of bank accounts

  • Utilized polymorphism to perform different operations on various account types

  • Applied abstraction to hide complex implementation details from users

  • Implemented interfaces to define common behaviors for different classes

View 1 answer
right arrow

Q15. Coding question : sort an array, use of streams to find names from employee object whose salary is greater than 50000

Ans.

Sort an array and use streams to find names of employees with salary > 50000

  • Sort the array using Arrays.sort() method

  • Use streams to filter employee objects with salary > 50000

  • Map the filtered employee objects to their names

View 1 answer
right arrow

Q16. Which version of JDK is your project using? How do you set JDK version of your project? Which Springboot version are you using in your project? Where and how will you specify settings for your project? What bui...

read more
Ans.

Our project is using JDK 11. We set JDK version in pom.xml. We are using Springboot version 2.5.4. Settings are specified in application.properties. We use Maven as build tool and JUnit for testing.

  • JDK 11 is specified in pom.xml file of the project

  • Springboot version 2.5.4 is used in the project

  • Settings for the project are specified in application.properties file

  • Maven is used as the build tool for the project

  • JUnit is used for testing the application

Add your answer
right arrow

Q17. What is javaa and when it developed

Ans.

Java is a high-level, class-based, object-oriented programming language developed by Sun Microsystems in 1995.

  • Java is platform-independent and can run on any device with a Java Virtual Machine (JVM)

  • It is widely used for developing web, mobile, and desktop applications

  • Java has a vast library of pre-built classes and APIs

  • Java is constantly evolving with new versions and updates

  • Examples of popular Java-based applications include Minecraft, Android OS, and Hadoop

Add your answer
right arrow

Q18. Why java is platform independent ?

Ans.

Java is platform independent due to its bytecode and JVM.

  • Java code is compiled into bytecode which is platform-independent.

  • JVM (Java Virtual Machine) interprets the bytecode and executes it on any platform.

  • This eliminates the need for recompilation of code for different platforms.

  • Java's write once, run anywhere (WORA) feature is possible due to platform independence.

View 2 more answers
right arrow

Q19. What is OpenFeign, and how is it used in microservices architecture?

Ans.

OpenFeign is a declarative web service client used to simplify the process of making HTTP requests in microservices architecture.

  • OpenFeign allows developers to define RESTful web services as interfaces and automatically generate the necessary implementation code.

  • It integrates seamlessly with Spring Cloud and other microservices frameworks to facilitate communication between services.

  • OpenFeign supports features like load balancing, circuit breakers, and fallbacks, making it a ...read more

Add your answer
right arrow

Q20. What are the consequences of excessively using synchronized blocks and methods in Java?

Ans.

Excessive use of synchronized blocks and methods in Java can lead to performance issues and potential deadlocks.

  • Decreased performance due to increased contention for locks

  • Potential deadlocks if multiple threads are waiting for each other to release locks

  • Increased complexity and difficulty in debugging and maintaining code

  • Use synchronized sparingly and consider alternatives like ConcurrentHashMap or Lock interface

Add your answer
right arrow

Q21. How can you determine the number of threads needed for your application?

Ans.

The number of threads needed for an application can be determined based on factors like the type of tasks, hardware resources, and performance requirements.

  • Consider the type of tasks your application needs to perform - CPU-bound tasks may benefit from more threads, while I/O-bound tasks may not.

  • Take into account the hardware resources available - more threads may be beneficial on a multi-core processor compared to a single-core processor.

  • Analyze the performance requirements o...read more

Add your answer
right arrow

Q22. Difference between Array and linkedlist ?

Ans.

Array is a fixed size data structure while LinkedList is dynamic in size.

  • Array uses contiguous memory allocation while LinkedList uses non-contiguous memory allocation.

  • Insertion and deletion operations are faster in LinkedList than in Array.

  • Accessing elements in Array is faster than in LinkedList.

  • Arrays are best suited for small-sized data while LinkedLists are best suited for large-sized data.

  • Arrays can store primitive data types as well as objects while LinkedLists can only...read more

View 2 more answers
right arrow

Q23. Difference between (==) and (.equals()) in java ?

Ans.

The (==) operator compares object references while (.equals()) compares object values.

  • The (==) operator checks if two objects refer to the same memory location.

  • (.equals()) method checks if two objects have the same value.

  • The (==) operator is faster than (.equals()) as it does not involve method invocation.

  • The (.equals()) method can be overridden to provide custom comparison logic.

  • Primitive types can be compared using (==) operator.

  • Example: String s1 = new String("hello"); Str...read more

View 2 more answers
right arrow

Q24. various types of design pattern

Ans.

Design patterns are reusable solutions to common software problems.

  • Creational patterns: Singleton, Factory, Abstract Factory, Builder, Prototype

  • Structural patterns: Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy

  • Behavioral patterns: Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor

View 2 more answers
right arrow

Q25. microservices vs monolithic, process to convert monolithic to microservices, connect sql db to microservice.

Ans.

Answering questions related to microservices vs monolithic architecture, process to convert monolithic to microservices, and connecting SQL DB to microservices.

  • Microservices architecture is a distributed approach where each service is independent and can be developed, deployed, and scaled separately.

  • Monolithic architecture is a traditional approach where the entire application is developed as a single unit.

  • To convert a monolithic application to microservices, identify the bus...read more

Add your answer
right arrow

Q26. Which type of data is returned by Callable interface?

Ans.

The Callable interface in Java returns a Future object.

  • Callable interface returns a Future object which represents the result of a computation that may not be available yet.

  • The Future object can be used to retrieve the result of the computation, check if it is done, or cancel the computation.

  • Example: Callable<Integer> task = () -> { return 42; }

Add your answer
right arrow

Q27. What is the implementation process for service registry and discovery?

Ans.

Service registry and discovery involves registering services and allowing clients to discover and connect to them.

  • Implement a service registry where services can register themselves with metadata

  • Use a service discovery mechanism for clients to find and connect to services

  • Implement health checks to ensure services are available and healthy

  • Use a load balancer to distribute traffic among multiple instances of a service

Add your answer
right arrow

Q28. What is the use of static methods?

Ans.

Static methods are used to access class-level data and perform operations that do not require an instance of the class.

  • Static methods can be called without creating an instance of the class

  • They are used to access class-level data and perform operations that do not require an instance of the class

  • Static methods cannot access non-static instance variables or methods

  • Examples include Math class methods like Math.max() and Math.min()

  • Static methods are often used for utility classe...read more

Add your answer
right arrow

Q29. What is inheritance and explain its type

Ans.

Inheritance is a mechanism in which a new class inherits properties and behaviors from an existing class.

  • Inheritance allows for code reusability and promotes the concept of hierarchical classification.

  • There are different types of inheritance in Java: single inheritance, multi-level inheritance, hierarchical inheritance, and multiple inheritance.

  • Example: Class B extends Class A, where Class B inherits properties and behaviors from Class A.

Add your answer
right arrow

Q30. What is serialization? What is the way to stop serialization?

Ans.

Serialization is the process of converting an object into a stream of bytes to store or transmit it. To stop serialization, mark a field as transient.

  • Serialization is used to save the state of an object and recreate it when needed.

  • To stop serialization of a field, mark it as transient in the class.

  • Example: private transient int sensitiveData;

Add your answer
right arrow

Q31. How can you get data of employees based on a desired location using streams in Java 8?

Ans.

Use Java 8 streams to filter employees based on desired location.

  • Use stream() method on the list of employees

  • Use filter() method to filter employees based on desired location

  • Use collect() method to collect the filtered employees into a new list

Add your answer
right arrow

Q32. Difference between interfce and abstract class with example

Ans.

Difference between interface and abstract class with example

  • Interface is a blueprint of a class, while abstract class is a partially implemented class

  • Interface can only have abstract methods, while abstract class can have both abstract and non-abstract methods

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

  • Example of interface: Runnable interface in Java

  • Example of abstract class: Animal class with abstract method 'makeSound'

Add your answer
right arrow

Q33. How mongodb was integrated in your application?

Ans.

MongoDB was integrated in the application by using the official Java driver and configuring connection settings.

  • Used the official MongoDB Java driver to interact with the database

  • Configured connection settings such as host, port, database name, and authentication credentials

  • Implemented CRUD operations using MongoDB Java driver methods

  • Utilized MongoDB aggregation framework for complex queries

Add your answer
right arrow

Q34. How to monitor health of your application?

Ans.

Monitor application health using metrics, logs, alerts, and performance monitoring tools.

  • Use monitoring tools like Prometheus, Grafana, or New Relic to track key metrics such as CPU usage, memory usage, response times, and error rates.

  • Implement logging to record important events and errors in your application. Use tools like ELK stack (Elasticsearch, Logstash, Kibana) for log analysis.

  • Set up alerts to notify you of any critical issues or anomalies in your application. Configu...read more

Add your answer
right arrow

Q35. How to call an API in a Microservice architecture?

Ans.

To call an API in a Microservice architecture, use HTTP requests or messaging protocols like gRPC.

  • Use HTTP requests to communicate between microservices

  • Implement RESTful APIs for easy integration

  • Leverage messaging protocols like gRPC for efficient communication

  • Consider using service discovery mechanisms for dynamic API calls

Add your answer
right arrow

Q36. What is compile time polymorphism and runtime polymorphism?

Ans.

Compile time polymorphism is achieved through method overloading, while runtime polymorphism is achieved through method overriding.

  • Compile time polymorphism is also known as static polymorphism.

  • It is achieved by having multiple methods in the same class with the same name but different parameters.

  • Example: method overloading in Java.

  • Runtime polymorphism is also known as dynamic polymorphism.

  • It is achieved by having a method in a superclass and a method with the same signature ...read more

Add your answer
right arrow

Q37. How ArrayList works internally?

Ans.

ArrayList is a dynamic array that can grow or shrink in size.

  • ArrayList internally uses an array to store elements.

  • It can dynamically increase or decrease its size as elements are added or removed.

  • It allows random access to elements using an index.

  • Insertion and deletion operations are slower than accessing elements.

  • It can store null and duplicate elements.

  • Example: ArrayList list = new ArrayList<>();

  • list.add("apple"); list.add("banana"); list.remove(0);

Add your answer
right arrow

Q38. Wher did you used in web micro services in your project

Ans.

Web microservices were used extensively in my previous project.

  • We used microservices architecture to break down the monolithic application into smaller, independent services.

  • Each microservice was responsible for a specific business function, such as user authentication or payment processing.

  • We used RESTful APIs to communicate between microservices and implemented load balancing and fault tolerance.

  • We also used containerization with Docker to deploy and manage the microservice...read more

Add your answer
right arrow

Q39. What is string pool. What is string literal?

Ans.

String pool is a memory area in Java heap where unique string literals are stored.

  • String pool is a part of Java heap memory where unique string literals are stored.

  • String literals are created using double quotes, e.g. "hello".

  • Strings created using the same literal will reference the same object in the string pool.

  • String pool helps in saving memory by reusing common string literals.

Add your answer
right arrow

Q40. What is collections and object with jvm.

Ans.

Collections are Java classes that provide a way to store and manipulate groups of objects.

  • Collections are used to store and organize multiple objects in Java.

  • They provide various data structures and algorithms for efficient manipulation of objects.

  • Examples of collections include ArrayList, LinkedList, HashSet, and HashMap.

View 1 answer
right arrow

Q41. Wher did you used core java in your project

Ans.

Core Java was used extensively in my project for implementing various functionalities.

  • Used core Java for implementing data structures and algorithms

  • Implemented multithreading using core Java

  • Used core Java for handling exceptions and error handling

  • Implemented various design patterns using core Java

  • Used core Java for implementing networking and socket programming

View 1 answer
right arrow

Q42. How you had done exception handling in spring.

Ans.

Exception handling in Spring is done using @ExceptionHandler annotation, @ControllerAdvice annotation, and custom exception classes.

  • Use @ExceptionHandler annotation in controller classes to handle specific exceptions.

  • Use @ControllerAdvice annotation to define global exception handling for all controllers.

  • Create custom exception classes by extending RuntimeException or Exception classes.

  • Use try-catch blocks to handle exceptions within the code.

View 2 more answers
right arrow

Q43. What is the concept of Object-Oriented Programming (OOP)?

Ans.

OOP is a programming paradigm based on the concept of objects, which can contain data in the form of fields and code in the form of procedures.

  • OOP focuses on creating objects that interact with each other to solve problems.

  • Encapsulation: Objects can hide their internal state and require interaction through defined interfaces.

  • Inheritance: Objects can inherit attributes and methods from other objects.

  • Polymorphism: Objects can take on multiple forms or have different behaviors b...read more

Add your answer
right arrow

Q44. What is an interface in the context of programming?

Ans.

An interface in programming is a blueprint of a class that defines a set of methods that a class must implement.

  • Interfaces in Java are used to achieve abstraction and multiple inheritance.

  • Interfaces contain only method signatures, not method bodies.

  • Classes can implement multiple interfaces but can only extend one class.

  • Example: interface Shape { void draw(); }

  • Example: class Circle implements Shape { public void draw() { // draw circle } }

Add your answer
right arrow

Q45. What is the difference between stringbuilder and stringbuffer?

Ans.

StringBuffer is synchronized and thread-safe, while StringBuilder is not synchronized and not thread-safe.

  • StringBuffer is synchronized, meaning it is thread-safe and can be used in multi-threaded environments.

  • StringBuilder is not synchronized, making it faster but not suitable for multi-threaded environments.

  • StringBuffer methods are synchronized, while StringBuilder methods are not synchronized.

  • Example: StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilde...read more

Add your answer
right arrow

Q46. Why String is immutable? And how to make it mutable?

Ans.

String is immutable to ensure its security and thread safety. It can be made mutable using StringBuilder or StringBuffer.

  • String is immutable to prevent modification of its value once created.

  • Immutable strings are thread-safe and can be safely shared among multiple threads.

  • To make a string mutable, we can use StringBuilder or StringBuffer classes.

  • StringBuilder is not thread-safe but provides better performance.

  • StringBuffer is thread-safe but has slightly lower performance comp...read more

Add your answer
right arrow

Q47. What is different between abstract class and interface

Ans.

Abstract class can have both abstract and non-abstract methods, while interface can only have abstract methods.

  • Abstract class can have constructors, fields, and methods, while interface cannot have any of these.

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

  • Abstract classes are used to define common behavior among subclasses, while interfaces are used to define a contract for classes to implement.

  • Example: Abstract class - Animal with abstrac...read more

Add your answer
right arrow

Q48. What is different between put patch method in spring boot

Ans.

The main difference between PUT and PATCH methods in Spring Boot is the level of data that is updated.

  • PUT method is used to update an entire resource, while PATCH method is used to update only specific fields of a resource.

  • PUT method requires the client to send the entire updated resource, while PATCH method only requires the client to send the specific fields that need to be updated.

  • PUT method is idempotent, meaning multiple identical requests will have the same effect as a ...read more

Add your answer
right arrow

Q49. How to connect to multiple data bases through springboot

Ans.

To connect to multiple databases through Spring Boot, you can configure multiple data sources and use JPA for each database.

  • Configure multiple data sources in application.properties or application.yml file

  • Create separate configuration classes for each data source

  • Use @Primary annotation to specify the primary data source

  • Use @Qualifier annotation to specify the secondary data sources

  • Inject the data sources in your repositories or services as needed

Add your answer
right arrow

Q50. What is the different between List and Set?

Ans.

List is an ordered collection of elements while Set is an unordered collection of unique elements.

  • List allows duplicate elements while Set does not.

  • List maintains the insertion order while Set does not guarantee any order.

  • List is implemented by ArrayList, LinkedList, etc. while Set is implemented by HashSet, TreeSet, etc.

  • Example: List - [1, 2, 3, 3, 4], Set - [1, 2, 3, 4]

Add your answer
right arrow

Q51. How u configure multiple data sources in spring

Ans.

Multiple data sources in Spring can be configured using Spring Boot's @Configuration annotation and @Bean annotation.

  • Use @Configuration annotation to define a configuration class for each data source

  • Use @Bean annotation to create DataSource objects for each data source

  • Use @Primary annotation to specify the primary data source if needed

View 1 answer
right arrow

Q52. Filter price below 200 using streams for a Product with name and pricd

Ans.

Filter products below $200 using streams in Java

  • Use stream.filter() to filter products with price below 200

  • Use lambda expression to define the filtering condition

  • Example: products.stream().filter(product -> product.getPrice() < 200).forEach(System.out::println)

Add your answer
right arrow

Q53. How to connect two database in single application

Ans.

To connect two databases in a single application, create two separate connection objects and use them as needed.

  • Create two separate connection objects for each database

  • Use the appropriate connection object for each database operation

  • Ensure that the connection details for each database are correct

  • Handle any errors that may occur during the connection process

Add your answer
right arrow

Q54. What is thread ?

Ans.

Thread is a lightweight sub-process that can run concurrently with other threads.

  • Threads allow for parallel execution of code

  • Multiple threads can run within a single process

  • Threads share the same memory space

  • Examples include GUI updates, network communication, and background tasks

View 1 answer
right arrow

Q55. A terminal operation terminates the flow of the stream. Eg collect() etc

Ans.

Terminal operations are used to terminate the stream and produce a result or a side-effect.

  • Terminal operations are the final operations that can be performed on a stream.

  • They produce a result or a side-effect, such as collecting the elements into a collection or printing them to the console.

  • Examples of terminal operations include collect(), forEach(), reduce(), and toArray().

Add your answer
right arrow

Q56. What is difference between servlet and jsp

Ans.

Servlet is a Java class that handles requests and responses, while JSP is a technology that simplifies the creation of dynamic web pages.

  • Servlet is a Java class that extends the capabilities of servers to respond to requests. It is used to create dynamic web content.

  • JSP is a technology that simplifies the creation of dynamic web pages by allowing Java code to be embedded in HTML pages.

  • Servlets are used to handle business logic, while JSP is used for presentation logic.

  • Servlet...read more

View 1 answer
right arrow

Q57. Explain oops concepts with examples

Ans.

OOPs concepts are fundamental principles in object-oriented programming, including inheritance, encapsulation, polymorphism, and abstraction.

  • Inheritance: Allows a class to inherit properties and behavior from another class. Example: Animal class can be inherited by Dog class.

  • Encapsulation: Bundling data and methods that operate on the data into a single unit. Example: Using private variables and public methods in a class.

  • Polymorphism: Ability of a method to do different thing...read more

Add your answer
right arrow

Q58. What is deadlock? How to avoid it?

Ans.

Deadlock is a situation in which two or more processes are unable to proceed because each is waiting for the other to release a resource.

  • Avoid circular wait by ensuring processes request resources in the same order.

  • Prevent hold and wait by requiring processes to request all needed resources at once.

  • Implement a timeout mechanism to break potential deadlocks.

  • Use resource allocation graphs to detect and prevent deadlocks.

  • Avoid nested locks and minimize the use of locks in critic...read more

Add your answer
right arrow

Q59. What is different between hashmap and hashtable

Ans.

HashMap is non-synchronized and allows null values, while Hashtable is synchronized and does not allow null keys or values.

  • HashMap is non-synchronized, meaning it is not thread-safe, while Hashtable is synchronized and thread-safe.

  • HashMap allows null values and one null key, while Hashtable does not allow null keys or values.

  • HashMap is generally preferred for non-thread-safe applications, while Hashtable is used in thread-safe scenarios.

Add your answer
right arrow

Q60. Difference between failsafe and fail fast and also its implementation

Ans.

Fail fast stops the program immediately upon encountering an error, while failsafe allows the program to continue running despite errors.

  • Fail fast: Stops program immediately upon error to prevent further damage. Example: NullPointerException in Java.

  • Failsafe: Allows program to continue running despite errors. Example: using try-catch blocks to handle exceptions.

Add your answer
right arrow

Q61. Difference between concurrent and generic collection

Ans.

Concurrent collections are thread-safe and allow multiple threads to access and modify the collection simultaneously, while generic collections are not thread-safe.

  • Concurrent collections in Java are part of the java.util.concurrent package and include classes like ConcurrentHashMap and CopyOnWriteArrayList.

  • Generic collections in Java are part of the java.util package and include classes like ArrayList and HashMap.

  • Concurrent collections use synchronization mechanisms to ensure...read more

Add your answer
right arrow

Q62. How will you fetch the 10 data in Spring boot

Ans.

Use Spring Data JPA repository with a method to fetch the first 10 data entries.

  • Create a Spring Data JPA repository interface for the entity you want to fetch data from.

  • Define a method in the repository interface that returns the first 10 data entries using the 'findFirst10By' naming convention.

  • Inject the repository interface in your service or controller class and call the method to fetch the data.

Add your answer
right arrow

Q63. Sort the filtered list in alphabetical order on names

Ans.

Sort the filtered list of names in alphabetical order

  • Use Arrays.sort() method to sort the array of strings

  • Implement a custom Comparator if needed for custom sorting criteria

  • Ensure to handle null values if present in the list

Add your answer
right arrow

Q64. What's java?

Ans.

Java is a high-level, object-oriented programming language used to develop applications for various platforms.

  • Java is platform-independent and can run on any device with a Java Virtual Machine (JVM)

  • It is known for its security features and is commonly used for developing web applications, mobile apps, and enterprise software

  • Java code is compiled into bytecode, which can be executed on any platform that has a JVM installed

  • Popular Java frameworks include Spring, Hibernate, and ...read more

View 1 answer
right arrow

Q65. when do we use finally block?

Ans.

Finally block is used to execute code after try-catch block, regardless of exception occurrence.

  • Used to release resources like database connections, file handles, etc.

  • Used to perform cleanup operations like closing streams, releasing locks, etc.

  • Used to execute code that must run regardless of exception occurrence.

  • Can be used without catch block, but not vice versa.

  • Example: try { //code } catch(Exception e) { //handle exception } finally { //cleanup code }

Add your answer
right arrow

Q66. What are terminal operations in Java 8?

Ans.

Terminal operations are the final operations in Java 8 streams that produce a result or a side-effect.

  • Terminal operations are invoked after intermediate operations on a stream.

  • They produce a result or a side-effect and terminate the stream.

  • Examples of terminal operations include forEach, reduce, collect, min, max, count, and anyMatch.

Add your answer
right arrow

Q67. What is difference between rest and soap

Ans.

REST is an architectural style for distributed hypermedia systems, while SOAP is a protocol for exchanging structured information in web services.

  • REST is lightweight and uses standard HTTP methods like GET, POST, PUT, DELETE, while SOAP uses XML for message format and relies on protocols like HTTP, SMTP, etc.

  • REST is stateless, meaning each request from a client to server must contain all the information needed to understand the request, while SOAP can maintain state between r...read more

Add your answer
right arrow

Q68. What are Spring boot actuators?

Ans.

Spring Boot Actuators are built-in tools that provide insight into the running application.

  • Actuators expose various endpoints to monitor and manage the application.

  • They can be used to check health, metrics, environment details, and more.

  • Examples include /actuator/health, /actuator/metrics, and /actuator/env.

Add your answer
right arrow

Q69. Find the number of times a word appeared in a file along with its line number and count

Ans.

The answer provides a Java code snippet to find the number of times a word appeared in a file along with its line number and count.

  • Read the file line by line

  • Split each line into words

  • Create a map to store word counts and line numbers

  • Iterate through each word and update the map

  • Format the map data into JSON

Add your answer
right arrow

Q70. What is the architecture of spring mvc

Ans.

Spring MVC follows a Model-View-Controller architecture where the controller receives the requests, processes them, and returns the response.

  • Controller: Handles incoming requests and delegates processing to the appropriate service

  • Model: Represents the data and business logic of the application

  • View: Renders the model data and sends it back to the client

  • DispatcherServlet: Front controller that receives all incoming requests and dispatches them to the appropriate controllers

  • Hand...read more

View 1 answer
right arrow

Q71. Difference between private and public

Ans.

Private members are accessible only within the same class, while public members can be accessed from any class.

  • Private members are used for encapsulation and data hiding.

  • Public members are used for providing access to the outside world.

  • Example: private int age; vs public String name;

Add your answer
right arrow

Q72. what is the meaning of string.

Ans.

A string is a sequence of characters used to represent text in programming.

  • Strings are often used for storing and manipulating text data.

  • In Java, strings are represented by the String class.

  • Strings can be concatenated using the + operator.

  • Strings are immutable, meaning they cannot be changed once created.

  • Examples of string literals include "hello world" and "42".

View 1 answer
right arrow

Q73. how to handle exception in spring boot?

Ans.

Exceptions in Spring Boot can be handled using try-catch blocks, @ExceptionHandler annotation, and global exception handling.

  • Use try-catch blocks to handle exceptions within a specific method.

  • Use @ExceptionHandler annotation to handle exceptions at the controller level.

  • Implement a global exception handler using @ControllerAdvice and @ExceptionHandler annotations.

  • Customize error responses using ResponseEntityExceptionHandler.

  • Use @ResponseStatus annotation to specify the HTTP s...read more

View 1 answer
right arrow

Q74. What is spring boot validation ?

Ans.

Spring Boot validation is a feature that allows developers to validate input data in a Spring Boot application.

  • Spring Boot validation is used to ensure that the data entered by the user meets certain criteria.

  • It can be applied to request parameters, request bodies, and path variables.

  • Annotations like @NotNull, @Size, @Email, etc., are commonly used for validation.

  • Custom validation logic can also be implemented using custom annotations and validators.

Add your answer
right arrow

Q75. what is the difference b/w spring and spring boot

Ans.

Spring is a framework for building Java applications, while Spring Boot is a tool that simplifies the setup and configuration of Spring applications.

  • Spring is a comprehensive framework that provides various modules for building Java applications, such as Spring MVC, Spring Security, and Spring Data.

  • Spring Boot is an opinionated tool that simplifies the setup and configuration of Spring applications by providing defaults and auto-configuration.

  • Spring Boot includes embedded ser...read more

Add your answer
right arrow

Q76. Difference between stack and heap memory?

Ans.

Stack memory is used for static memory allocation and execution of thread-specific variables, while heap memory is used for dynamic memory allocation.

  • Stack memory is used for static memory allocation, such as local variables and function call stack.

  • Heap memory is used for dynamic memory allocation, such as objects created using 'new' keyword.

  • Stack memory is limited in size and typically faster to access, while heap memory is larger and slower to access.

  • Stack memory is automat...read more

View 1 answer
right arrow

Q77. How to sort a string using lambda expression

Ans.

Sort a string using lambda expression

  • Convert the string to an array of characters

  • Use the Arrays.sort() method with a lambda expression as the comparator

  • Join the sorted characters back into a string

Add your answer
right arrow

Q78. what is the use of index?

Ans.

Index is used to improve the performance of database queries by allowing faster access to specific data.

  • Indexes are created on database tables to speed up the retrieval of data.

  • They work by creating a separate data structure that allows for faster access to specific data.

  • Indexes can be created on one or more columns of a table.

  • Examples of indexes include primary keys, unique indexes, and clustered indexes.

Add your answer
right arrow

Q79. what is encapsulation ?

Ans.

Encapsulation is the process of hiding implementation details and providing access to only necessary information.

  • Encapsulation helps in achieving data abstraction and information hiding.

  • It allows for better control over data and prevents unauthorized access.

  • In Java, encapsulation is achieved through the use of access modifiers such as private, public, and protected.

  • For example, a class may have private variables that can only be accessed through public methods.

  • This ensures th...read more

View 1 answer
right arrow

Q80. What are the type of bean scope

Ans.

Bean scope in Java includes singleton, prototype, request, session, and application scopes.

  • Singleton scope: Default scope, only one instance per Spring container.

  • Prototype scope: New instance created each time bean is requested.

  • Request scope: Bean created for each HTTP request.

  • Session scope: Bean created for each HTTP session.

  • Application scope: Bean created once for entire web application.

Add your answer
right arrow

Q81. Security measures used in current project

Ans.

The security measures used in the current project include encryption, authentication, and regular security audits.

  • Encryption is used to protect sensitive data in transit and at rest.

  • Authentication mechanisms such as multi-factor authentication and access control lists are implemented to ensure only authorized users can access the system.

  • Regular security audits are conducted to identify and address any vulnerabilities in the system.

  • Firewalls and intrusion detection systems are...read more

Add your answer
right arrow

Q82. What is SQL and java structure

Ans.

SQL is a language used to manage relational databases. Java is a programming language used for developing applications.

  • SQL is used to create, modify, and query databases

  • Java is used to write code for applications that interact with databases

  • Java has built-in libraries for connecting to databases using JDBC

  • SQL and Java can be used together to create dynamic web applications

Add your answer
right arrow

Q83. Write program to identify vowels and replace them in string

Ans.

Program to identify and replace vowels in a string

  • Create a function that takes a string as input

  • Iterate through each character in the string and check if it is a vowel (a, e, i, o, u)

  • If a character is a vowel, replace it with a different character

Add your answer
right arrow

Q84. What is java where uses java

Ans.

Java is a popular programming language used for developing various applications and software.

  • Java is used for developing desktop, web, and mobile applications.

  • It is also used for developing enterprise-level software and games.

  • Java is widely used in the financial industry for developing trading applications and risk management systems.

  • It is also used in the healthcare industry for developing electronic medical records and patient management systems.

  • Java is used for developing ...read more

Add your answer
right arrow

Q85. What do u know about Java?

Ans.

Java is a high-level, object-oriented programming language used for developing desktop, web, and mobile applications.

  • Java is platform-independent and can run on any operating system

  • It is known for its security features and is widely used for developing enterprise-level applications

  • Java has a vast library of pre-built classes and APIs that make development faster and easier

  • It supports multithreading, allowing multiple threads to run simultaneously within a single program

  • Java i...read more

Add your answer
right arrow

Q86. Difference between web server and application server

Ans.

Web server handles HTTP requests and responses, while application server executes business logic and supports dynamic content.

  • Web server serves static content like HTML, CSS, and images (e.g. Apache, Nginx)

  • Application server executes server-side code and supports dynamic content (e.g. Tomcat, JBoss)

  • Web server can be used without an application server, but not vice versa

View 1 answer
right arrow

Q87. difference between interface and abstract class

Ans.

Interface defines only method signatures while abstract class can have both method signatures and implementations.

  • Abstract class can have constructors while interface cannot

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

  • Abstract class can have non-abstract methods while interface cannot

  • Abstract class is used for creating a base class while interface is used for implementing a contract

  • Example: Abstract class - Animal, Interface - Flyable

Add your answer
right arrow

Q88. Tell me spring boot Annotation?

Ans.

Spring Boot annotations are used to simplify the development process by providing shortcuts for common tasks.

  • Annotations like @SpringBootApplication, @RestController, @Autowired, @GetMapping, @PostMapping are commonly used in Spring Boot applications.

  • These annotations help in configuring the application, defining REST endpoints, injecting dependencies, and mapping HTTP requests to controller methods.

  • For example, @SpringBootApplication is used to mark the main class of a Sprin...read more

Add your answer
right arrow

Q89. Given an array check whether pair exist with given sun

Ans.

Check if a pair exists in an array with a given sum

  • Iterate through the array and store the difference between the target sum and each element in a HashSet

  • For each element, check if the element exists in the HashSet

  • Return true if a pair is found, otherwise return false

Add your answer
right arrow

Q90. Discuss Internal's of concurrent hashmap provided by java collection framework

Ans.

ConcurrentHashMap in Java provides thread-safe operations for high concurrency applications.

  • Uses separate chaining for handling collisions

  • Implements lock stripping to reduce contention

  • Supports full concurrency for read operations

  • Introduced in Java 5 to address performance issues with Hashtable

Add your answer
right arrow

Q91. Difference between string buffer &amp; string builder

Ans.

String buffer is synchronized while string builder is not.

  • String buffer is thread-safe while string builder is not.

  • String buffer is slower than string builder.

  • String builder is preferred for single-threaded operations.

  • Both classes are used for manipulating strings.

  • Example: StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();

Add your answer
right arrow

Q92. Exception handling &amp; types of exception handling

Ans.

Exception handling is a mechanism to handle runtime errors. There are two types of exceptions: checked and unchecked.

  • Checked exceptions are checked at compile-time and must be handled or declared in the method signature.

  • Unchecked exceptions are not checked at compile-time and can be handled using try-catch or thrown to the calling method.

  • Common exceptions include NullPointerException, ArrayIndexOutOfBoundsException, and IOException.

  • Exception handling can improve program robus...read more

Add your answer
right arrow

Q93. Synchronous vs Asynchronous communication

Ans.

Synchronous communication is blocking, while asynchronous communication is non-blocking.

  • Synchronous communication waits for a response before continuing, while asynchronous communication does not wait.

  • Examples of synchronous communication include traditional function calls, while examples of asynchronous communication include callbacks and promises.

  • Synchronous communication can lead to performance issues if there are delays in responses, while asynchronous communication can i...read more

Add your answer
right arrow

Q94. How to customise server in spring

Ans.

To customise server in Spring, you can modify server configurations, add custom filters, interceptors, and listeners.

  • Modify server configurations in application.properties or application.yml file

  • Add custom filters using @Component annotation and implementing Filter interface

  • Implement custom interceptors by extending HandlerInterceptorAdapter class

  • Register custom listeners by implementing ApplicationListener interface

Add your answer
right arrow

Q95. DI in Spring

Ans.

Dependency Injection (DI) is a design pattern used in Spring framework to manage object dependencies.

  • DI allows objects to be loosely coupled, making them easier to test and maintain.

  • In Spring, DI is achieved through inversion of control (IoC) container.

  • There are three types of DI in Spring: constructor injection, setter injection, and field injection.

  • Example: @Autowired annotation in Spring is used for DI.

  • DI promotes reusability, modularity, and separation of concerns.

View 1 answer
right arrow

Q96. What is bean scope in spring?

Ans.

Bean scope in Spring determines the lifecycle and visibility of a bean in the Spring container.

  • Bean scope defines how long a bean lives and how many instances are created

  • Common scopes include singleton, prototype, request, session, and application

  • Singleton scope creates a single instance per Spring container, prototype creates a new instance each time it is requested

Add your answer
right arrow

Q97. What is the dependency injection

Ans.

Dependency injection is a design pattern in which the dependencies of an object are provided externally rather than created within the object itself.

  • Dependency injection helps in achieving loose coupling between classes.

  • It allows for easier testing by providing mock dependencies.

  • There are three types of dependency injection: constructor injection, setter injection, and interface injection.

  • Example: Spring framework uses dependency injection to manage object dependencies.

Add your answer
right arrow

Q98. Q1: what is interface

Ans.

An interface is a collection of abstract methods and constants that can be implemented by a class.

  • Interfaces define a contract that a class must follow if it implements the interface.

  • Interfaces can be used to achieve abstraction and polymorphism in Java.

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

  • Examples of interfaces in Java include Serializable, Comparable, and Runnable.

Add your answer
right arrow

Q99. How many ways to create a thread in Java

Ans.

There are multiple ways to create a thread in Java, including extending the Thread class, implementing the Runnable interface, and using Java 8's lambda expressions.

  • Extending the Thread class

  • Implementing the Runnable interface

  • Using Java 8's lambda expressions

Add your answer
right arrow

Q100. What is comparable and comparator?

Ans.

Comparable and Comparator are interfaces in Java used for sorting objects.

  • Comparable is used to define the natural ordering of objects.

  • Comparator is used to define custom ordering of objects.

  • Comparable is implemented by the class whose objects need to be sorted.

  • Comparator is a separate class that implements the compare() method.

  • Comparable uses the compareTo() method to compare objects.

  • Comparator uses the compare() method to compare objects.

  • Comparable is used when the sorting ...read more

Add your answer
right arrow
1
2
Next
Contribute & help others!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos

Interview Process at TCS Java Developer

based on 171 interviews
4 Interview rounds
Technical Round - 1
Technical Round - 2
HR Round - 1
HR Round - 2
View more
interview tips and stories logo
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Top Java Developer Interview Questions from Similar Companies

NeoSOFT Logo
3.9
 • 18 Interview Questions
ITCS Logo
3.3
 • 11 Interview Questions
ITC Infotech  Logo
3.8
 • 10 Interview Questions
View all
Recently Viewed
INTERVIEWS
TCS
70 top interview questions
DESIGNATION
INTERVIEWS
Wipro
No Interviews
INTERVIEWS
Wipro
No Interviews
INTERVIEWS
Wipro
No Interviews
INTERVIEWS
Wipro
No Interviews
INTERVIEWS
Wipro
No Interviews
REVIEWS
Tata Motors
No Reviews
INTERVIEWS
Jio
No Interviews
DESIGNATION
Share an Interview
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
70 Lakh+

Reviews

5 Lakh+

Interviews

4 Crore+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter