Newgen Software Technologies
TCS Interview Questions and Answers
Q1. Write a SQL query to find third highest salary from employee table.
SQL query to find third highest salary from employee table.
Use the ORDER BY clause to sort the salaries in descending order
Use the LIMIT clause to limit the result to the third row
Use a subquery to exclude the highest and second highest salaries
Q2. Write a program to count occurance the letter in a string.
This program counts the occurrence of each letter in a given string.
Use a HashMap to store the count of each letter.
Iterate through the characters of the string and update the count in the HashMap.
Finally, print the count of each letter.
Q3. What is the default size of an arraylist.
The default size of an ArrayList is 10.
The default initial capacity of an ArrayList is 10.
If the number of elements exceeds the initial capacity, the ArrayList automatically increases its size.
The capacity of an ArrayList can be increased manually using the ensureCapacity() method.
Q4. what is servlet life cycle
Servlet life cycle refers to the sequence of events that occur during the lifespan of a servlet.
Servlet is loaded into memory when the server starts
init() method is called to initialize the servlet
service() method is called to handle client requests
destroy() method is called when the servlet is removed from memory
Servlet can be reloaded if the server is restarted
Q5. what is try with resources
Try with resources is a feature introduced in Java 7 to automatically close resources after use.
It simplifies the code by eliminating the need for a finally block to close the resource
The resource must implement the AutoCloseable interface
Multiple resources can be declared in a single try-with-resources statement
Example: try(FileInputStream fis = new FileInputStream("file.txt")) { //code }
Q6. Difference between Array and arraylist.
Array is a fixed-size data structure while ArrayList is a dynamic-size data structure in Java.
Array has a fixed length, while ArrayList can grow dynamically.
Array can store both primitive types and objects, while ArrayList can only store objects.
Array uses square brackets [] for declaration, while ArrayList uses angle brackets <>.
Array provides direct access to elements using index, while ArrayList provides methods for accessing and manipulating elements.
Example: String[] nam...read more
Q7. Explain OOPs concepts.
OOPs concepts are fundamental principles of object-oriented programming that help in designing and implementing software solutions.
Encapsulation: Bundling data and methods together in a class.
Inheritance: Creating new classes by inheriting properties and behaviors from existing classes.
Polymorphism: Ability of an object to take on many forms.
Abstraction: Hiding complex implementation details and providing a simplified interface.
Encapsulation, inheritance, and polymorphism tog...read more
Q8. Explain working of Arraylist.
ArrayList is a dynamic array that can grow or shrink in size. It stores objects and provides methods for adding, removing, and accessing elements.
ArrayList is part of the Java Collections Framework.
It is implemented as a resizable array.
Elements can be added using the add() method.
Elements can be accessed using the get() method.
Elements can be removed using the remove() method.
The size() method returns the number of elements in the ArrayList.
Example: ArrayList
names = new Arr...read more
Interview Process at TCS
Top Java Developer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month