HCLTech
50+ TCS Interview Questions and Answers
Q1. Remove Duplicates from String Problem Statement
You are provided a string STR
of length N
, consisting solely of lowercase English letters.
Your task is to remove all duplicate occurrences of characters in the s...read more
Q2. Number of Islands Problem Statement
You are provided with a 2-dimensional matrix having N
rows and M
columns, containing only 1s (land) and 0s (water). Your goal is to determine the number of islands in this ma...read more
Q3. Difference between array list and linked list..where do we use ?
Array list stores elements in contiguous memory locations, while linked list stores elements in nodes with pointers to the next node.
Array list allows fast access to elements using index, while linked list allows for fast insertion and deletion of elements.
Array list is ideal for scenarios where random access is required, while linked list is suitable for scenarios where frequent insertion and deletion operations are needed.
Example: Array list is used in scenarios where eleme...read more
Q4. Process builder. 2.types of relationships. 3.difference in user ,profile and role. 4.workflow. 5.Admin questions
Answering questions related to software development and Salesforce administration.
Process Builder is a visual tool in Salesforce used to automate business processes.
Types of relationships in Salesforce include lookup, master-detail, and many-to-many relationships.
User represents an individual who can log in and access Salesforce, Profile defines the permissions and settings for a user, and Role determines the hierarchy and access levels within an organization.
Workflow in Sale...read more
Q5. Write a code to find out which pairs in the array list will give the sum as 8
Code to find pairs in array list with sum 8
Iterate through array and check if pair sum is 8
Use a hashmap to store elements and their complements
Time complexity O(n)
Q6. How to communicate two api’s in springboot.Explain the implementation
To communicate two APIs in Spring Boot, you can use RestTemplate or WebClient to make HTTP requests.
Use RestTemplate to make synchronous HTTP requests between APIs
Use WebClient to make asynchronous HTTP requests between APIs
Implement error handling and exception handling for robust communication
Consider using Feign client for declarative REST client
Ensure proper authentication and authorization mechanisms are in place
Q7. What is the restcontroller and controller annotation
RestController and Controller annotations are used in Spring framework to define classes as controllers for handling HTTP requests.
RestController annotation is used to define a class as a RESTful web service controller, which returns data in JSON or XML format.
Controller annotation is used to define a class as a traditional Spring MVC controller, which returns a view to the client.
Both annotations are used to handle HTTP requests and map them to specific methods in the contro...read more
Q8. What is meant by @data annotation and @value annotation
The @Data annotation is used in Java to declare a class as a data class, while the @Value annotation is used in Spring to create immutable objects.
The @Data annotation in Java is used to generate getters, setters, toString, equals, and hashCode methods for a class.
The @Value annotation in Spring is used to create immutable objects with final fields that are initialized through constructor injection.
Both annotations help in reducing boilerplate code and improving code readabil...read more
Q9. How to read the values from application properties file
To read values from application properties file, use a properties file reader in the programming language being used.
Use a properties file reader class in the programming language being used (e.g. Properties class in Java).
Load the properties file using the reader class.
Access the values using keys specified in the properties file.
Q10. What is meant by @qualifier and @autowired
Annotations used in Spring framework for dependency injection
Used in Spring framework to inject dependencies
Qualifier is used to specify which bean to autowire when multiple beans of the same type exist
Autowired is used to automatically inject the dependency
Q11. Write a code to print the even numbers as well as the squares of it in java8
Code to print even numbers and their squares in Java8
Use Java8 Stream API to generate even numbers
Map each even number to its square using map() function
Print the even numbers and their squares using forEach() function
Q12. How to make a specific
To make a specific what? Please provide more context.
Please provide more information about what needs to be made specific
Clarify the scope and purpose of the specific thing
Consider using clear and concise language to define the specific thing
Q13. What is meant by @configuration annotation
Annotation used in Spring framework to indicate that a class declares one or more @Bean methods
Used in Spring framework to define configuration classes
Indicates that a class should be considered as a source of bean definitions
Helps Spring to understand the configuration and create beans accordingly
Q14. What are the intermediate operations in java8
Intermediate operations in Java 8 are used to process the stream elements and produce a new stream as output.
Intermediate operations are lazy and do not start processing the stream until a terminal operation is invoked.
Examples of intermediate operations include filter, map, sorted, distinct, limit, and skip.
Intermediate operations can be chained together to form a pipeline of operations on a stream.
Q15. code to use MultivaluedMap and add list of values to a particular key
Using MultivaluedMap to add a list of values to a particular key in Java
Create a MultivaluedMap object from Apache Commons Collections library
Use the put method to add a key-value pair where the value is a list of values
Use the get method to retrieve the list of values for a particular key
Q16. What is multi threading
Multi threading is the ability of a program to perform multiple tasks concurrently.
It allows for better utilization of CPU resources
It can improve program performance and responsiveness
Examples include web servers handling multiple requests simultaneously
It requires careful management of shared resources to avoid race conditions
Q17. What is the usage of method reference
Method reference is a shorthand syntax for lambda expressions to call a method.
Method reference can be used to refer to static methods, instance methods, and constructors.
It helps in improving code readability and conciseness.
Example: list.forEach(System.out::println) is equivalent to list.forEach(item -> System.out.println(item)).
Q18. What is the use of static class
Static class is used to create classes that cannot be instantiated and can only have static members.
Static class cannot be instantiated, meaning you cannot create an object of a static class.
Static class can only have static members such as static fields, methods, properties, and events.
Static classes are commonly used for utility classes where all members are static and do not require an instance to be accessed.
Q19. Can we create multiple objects
Yes, we can create multiple objects in programming.
Objects are instances of a class.
We can create multiple objects of the same class.
Each object has its own set of instance variables and methods.
Objects can interact with each other through their methods.
Example: creating multiple instances of a 'Person' class for different people.
Q20. What are types of encapsulation
Encapsulation types are data, procedural and combination.
Data encapsulation hides data from outside world and provides access through methods.
Procedural encapsulation hides implementation details of a procedure.
Combination encapsulation is a mix of data and procedural encapsulation.
Examples include private variables in a class, access modifiers in Java, etc.
Q21. Tell me about java, till what you learn
Java is a popular object-oriented programming language used for developing various applications.
Java was developed by Sun Microsystems in 1995.
It is platform-independent and can run on any operating system.
Java is used for developing web applications, mobile applications, desktop applications, and games.
It is known for its security features and is widely used in enterprise applications.
Java has a vast library of pre-built classes and APIs that make development faster and easi...read more
Q22. Write a sample code using @functional annotation
Sample code using @functional annotation
Use @FunctionalInterface annotation to declare a functional interface in Java
Functional interfaces have exactly one abstract method
Example: @FunctionalInterface interface MyFunctionalInterface { void myMethod(); }
Q23. What configuration i have done.
I have configured various software systems and tools for development purposes.
Configured IDEs such as Eclipse and Visual Studio for development
Set up version control systems like Git and SVN
Installed and configured build tools like Maven and Gradle
Configured application servers like Tomcat and JBoss
Set up databases like MySQL and Oracle for development and testing
Q24. What is abstaction and abstrcat class
Abstraction is the process of hiding complex implementation details and providing a simplified interface.
Abstraction allows us to focus on the essential features of an object or system while ignoring the irrelevant details.
An abstract class is a class that cannot be instantiated and is meant to be subclassed.
Abstract classes can have both abstract and non-abstract methods.
Abstract classes are used to define common behavior and characteristics that can be inherited by subclass...read more
Q25. What are the features of java8
Java 8 introduced several new features including lambda expressions, functional interfaces, streams, and the new date and time API.
Lambda expressions allow you to write code in a more concise and readable way.
Functional interfaces provide a way to define interfaces with a single abstract method.
Streams allow for processing sequences of elements in a functional style.
The new date and time API provides improved date and time handling capabilities.
Q26. Difference between restcontroller and controller
Restcontroller is used for RESTful web services while controller is used for traditional web applications.
RestController is a specialized version of @Controller
RestController returns data in JSON or XML format
Controller returns a view to be rendered by the browser
RestController is used for building RESTful web services
Controller is used for traditional web applications
Example: @RestController vs @Controller in Spring MVC
Q27. what is the static variable do in c
Static variables in C are variables that retain their value between function calls.
Static variables are initialized only once, at the start of the program execution.
They retain their value throughout the program's execution.
Static variables are stored in the data segment of the program's memory.
They have a default value of 0 if not explicitly initialized.
Q28. What is stream in java8
Streams in Java 8 are sequences of elements that support functional-style operations.
Streams allow for processing sequences of elements in a functional way
They can be created from collections, arrays, or I/O resources
Common operations on streams include map, filter, reduce, and collect
Q29. what is shallow copy n javascrpt
Shallow copy in JavaScript creates a new object and copies the references of the original object's properties.
Shallow copy only copies the top-level properties of an object, not nested objects.
Changes to the nested objects in the copied object will affect the original object.
Shallow copy can be done using Object.assign() or spread operator.
Q30. What is use of static variables
Static variables are used to store values that are shared among all instances of a class or function.
Static variables retain their value between function calls
They are initialized only once at the start of the program
Useful for maintaining state across multiple function calls
Q31. What is immutable class
Immutable class is a class whose instances cannot be modified after creation.
Immutable class instances have all fields as final and private.
Immutable classes have no setter methods, only getter methods.
Examples of immutable classes in Java are String, Integer, and LocalDate.
Q32. What is parallel stream
Parallel stream is a feature in Java that allows processing elements of a stream concurrently.
Parallel stream can be created from a regular stream using parallel() method.
It utilizes multiple threads to process elements in parallel, improving performance for large datasets.
However, parallel stream may not always be faster than sequential stream due to overhead of managing multiple threads.
Example: List
list = Arrays.asList("apple", "banana", "cherry"); list.parallelStream().f...read more
Q33. What is object ?
An object is an instance of a class that encapsulates data and behavior.
Objects have attributes (data) and methods (behavior).
Objects can interact with each other through method calls.
Objects can be created from classes.
Examples of objects include a car, a person, or a bank account.
Q34. Difference between map and flatmap
Map applies a function to each element in a collection and returns a new collection. FlatMap applies a function that returns a collection for each element and flattens the result into a single collection.
Map transforms each element of a collection using a function and returns a new collection of the same size.
FlatMap transforms each element of a collection using a function that returns a collection, then flattens the result into a single collection.
Example: map([1, 2, 3], x =...read more
Q35. What is java 8 stream
Java 8 Stream is a sequence of elements that can be processed in parallel or sequentially.
Stream is not a data structure, it does not store elements
Stream operations are divided into intermediate and terminal operations
Intermediate operations return a new stream and terminal operations return a result
Example: stream.filter(x -> x > 5).map(x -> x * 2).forEach(System.out::println)
Example: stream.reduce(0, (a, b) -> a + b)
Q36. what is volatile will do in c
In C, 'volatile' keyword is used to indicate that a variable may be changed unexpectedly by external factors.
Prevents compiler optimizations that assume the variable's value will not change
Useful for variables accessed by multiple threads or hardware devices
Example: volatile int x; // 'x' may be changed by hardware interrupts
Q37. What is singleton
Singleton is a design pattern that restricts the instantiation of a class to one object.
Ensures a class has only one instance and provides a global point of access to it
Commonly used in scenarios where only a single instance of a class is needed, such as database connections or configuration settings
Implemented by creating a static method that returns the same instance of the class every time it is called
Q38. What is oops, main pillars
Object-oriented programming (OOP) is a programming paradigm based on the concept of objects.
OOP is a programming approach that focuses on creating objects that contain both data and methods.
The main pillars of OOP are encapsulation, inheritance, and polymorphism.
Encapsulation allows objects to hide their internal state and expose only necessary information.
Inheritance enables the creation of new classes based on existing classes, inheriting their properties and behaviors.
Poly...read more
Q39. What is static vs singleton
Static vs Singleton: Static refers to a class member that belongs to the class itself, while Singleton is a design pattern that restricts the instantiation of a class to a single object.
Static members are shared among all instances of a class, while Singleton ensures only one instance of a class exists.
Static members can be accessed without creating an object, while Singleton requires instantiation.
Static members are typically used for utility methods or constants, while Sing...read more
Q40. What is collection
A collection is a group of related objects or data items that are stored together.
Collections can be used to store and manipulate multiple items of the same type.
Examples of collections include arrays, lists, sets, and maps.
Collections provide methods for adding, removing, and accessing items in the group.
Q41. write sql for 3rd highest salary
Use SQL query with subquery to find 3rd highest salary in a table.
Use ORDER BY and LIMIT to get the 3rd highest salary.
Use a subquery to exclude the top 2 highest salaries before selecting the 3rd highest.
Q42. deff between union and union all
Union combines and removes duplicates, Union All combines all rows including duplicates.
Union removes duplicates, Union All includes duplicates
Union is slower than Union All as it has to remove duplicates
Union requires the same number of columns in both queries, Union All does not
Q43. what is hibernate,kafka,gcp
Hibernate is an ORM framework for Java, Kafka is a distributed event streaming platform, and GCP is Google Cloud Platform.
Hibernate is an ORM (Object-Relational Mapping) framework that simplifies database interactions in Java applications.
Kafka is a distributed event streaming platform used for building real-time data pipelines and streaming applications.
GCP (Google Cloud Platform) is a suite of cloud computing services offered by Google for storage, computing, and data analy...read more
Q44. what is Dependency Injection
Dependency Injection is a design pattern where components are given their dependencies rather than creating them internally.
Allows for better code reusability and testability
Promotes loose coupling between components
Commonly used in frameworks like Spring for Java
Example: Instead of a class creating an instance of another class it needs, the instance is provided externally
Q45. what is garbage collector
Garbage collector is a program that automatically manages memory by reclaiming unused memory.
Automatically frees up memory that is no longer in use
Prevents memory leaks by reclaiming unused memory
Examples include Java's garbage collector and C#'s garbage collector
Q46. what is hashmap
HashMap is a data structure that stores key-value pairs and allows for fast retrieval of values based on keys.
HashMap is part of the Java Collections framework.
It uses hashing to store elements in key-value pairs.
It allows for quick retrieval of values based on keys.
Example: HashMap
map = new HashMap<>();
Q47. You know any computer skills
Yes, I have a strong foundation in computer skills including programming languages, databases, and software development tools.
Proficient in programming languages such as Java, Python, and C++
Experience with databases like MySQL and MongoDB
Familiarity with software development tools like Git and Jira
Q48. What is expectation
Expectation is a belief about what will happen in the future or what should happen in a particular situation.
Expectation is a mental state anticipating a certain outcome.
It can be based on past experiences, assumptions, or desires.
Expectations can influence behavior and emotions.
Unmet expectations can lead to disappointment or frustration.
Examples: Expecting a promotion after working hard, expecting a package to arrive on time.
Q49. OOPS concepts in java
OOPS concepts in Java refer to Object-Oriented Programming principles like Inheritance, Encapsulation, Polymorphism, and Abstraction.
Inheritance: Allows a class to inherit properties and behavior from another class.
Encapsulation: Bundling data and methods that operate on the data into a single unit.
Polymorphism: Ability to present the same interface for different data types.
Abstraction: Hiding the implementation details and showing only the necessary features of an object.
Q50. what is jsx in react
JSX is a syntax extension for JavaScript used in React to write HTML elements in JavaScript code.
JSX allows developers to write HTML-like code in JavaScript files
It makes the code more readable and easier to understand
JSX elements are transpiled into regular JavaScript by tools like Babel
Q51. What is Volatile
Volatile keyword in programming is used to indicate that a variable's value can be changed unexpectedly.
Volatile keyword is used in multithreaded programming to ensure that the variable's value is always read from memory and not cached.
It is commonly used when working with hardware registers or shared variables in concurrent programming.
Example: volatile int x = 10; // variable x is marked as volatile to prevent compiler optimizations
Q52. Diff b/w set and orderedset
Set is an unordered collection of unique elements, while ordered set is a collection of unique elements with a defined order.
Set does not maintain any specific order of elements, while ordered set maintains the order of elements based on insertion.
In a set, elements are stored in a random order, while in an ordered set, elements are stored in the order they were inserted.
Examples of sets include {1, 2, 3} while examples of ordered sets include {3, 1, 2}.
Q53. y changing the company
I am looking for new challenges and opportunities for growth.
Seeking new challenges to expand my skills and knowledge
Interested in working on different projects and technologies
Hoping to advance my career and take on more responsibilities
Q54. 4 priniples of OOPS
4 principles of OOPS are Inheritance, Encapsulation, Abstraction, and Polymorphism.
Inheritance allows a class to inherit properties and behavior from another class.
Encapsulation restricts access to certain components within a class.
Abstraction hides complex implementation details and only shows necessary features.
Polymorphism allows objects to be treated as instances of their parent class.
Top HR Questions asked in TCS
Interview Process at TCS
Top Software Developer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month