Scan-IT
TCS Interview Questions and Answers
Q1. What is Reflection class in java
Reflection class in Java provides a way to examine or modify the behavior of methods, classes, interfaces at runtime.
Reflection allows accessing private fields, methods, and constructors of a class.
It enables dynamic loading of classes and creation of new objects.
Used in frameworks like Spring and Hibernate for dependency injection and object-relational mapping.
Example: Class.forName("com.example.MyClass") returns the Class object for the given class name.
Q2. SQL Query to get top 10 salary from employee table
SQL query to retrieve top 10 salaries from employee table.
Use SELECT statement to retrieve data from employee table
Use ORDER BY clause to sort the data in descending order based on salary
Use LIMIT clause to limit the result set to top 10 salaries
Q3. Contract between hashcode and equals method
The contract between hashCode and equals method is that if two objects are equal according to equals method, their hash codes must be equal as well.
The hashCode method returns an integer value that represents the object's unique identifier.
The equals method is used to compare two objects for equality.
According to the contract, if two objects are equal, their hash codes must be equal.
If the hashCode method is overridden, the equals method should also be overridden to maintain ...read more
Q4. 1.What is Reflection in java
Reflection in Java allows programmatic access to information about the fields, methods, and constructors of loaded classes.
Reflection provides the ability to examine and modify the behavior of classes, interfaces, and objects at runtime.
It allows accessing and manipulating fields, methods, and constructors that are otherwise inaccessible.
Reflection is commonly used in frameworks, libraries, and tools that require runtime analysis and modification of code.
Example: Retrieving t...read more
Q5. String equals and == method
The equals() method compares the content of two strings, while the == operator compares their references.
The equals() method returns true if the content of two strings is the same.
The == operator returns true if the references of two strings are the same.
Example: String str1 = "Hello"; String str2 = new String("Hello"); str1.equals(str2) returns true, but str1 == str2 returns false.
Q6. explain oops concept
OOPs (Object-Oriented Programming) is a programming paradigm based on the concept of objects, which can contain data and code.
OOPs focuses on creating objects that interact with each other to solve problems
Key concepts include encapsulation, inheritance, polymorphism, and abstraction
Encapsulation involves bundling data and methods that operate on the data into a single unit
Inheritance allows one class to inherit properties and behavior from another class
Polymorphism allows ob...read more
Interview Process at TCS
Top Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month