NIMAP INTERVIEW
NIMAP INTERVIEW
6. What is Inheritance?
Inheritance is when a class (child) inherits properties and methods from another class (parent)
using the extends keyword.
It helps in code reusability and method overriding.
7. What is Encapsulation?
Encapsulation is wrapping data (variables) and methods into a single unit (class).
It hides internal details using access modifiers and improves security and maintainability.
8. What is Polymorphism?
Polymorphism means the ability of an object to take many forms.
In Java, it's achieved through method overloading (compile-time) and method overriding
(runtime).
35. Hashing:
Hashing is a technique to convert data into a fixed-size hash code (using a hash function).
Used in data structures like HashMap and HashSet for fast access (average O(1)).
SQL
41. What is SQL?
SQL (Structured Query Language) is a standard programming language used to manage and
manipulate relational databases.
It allows you to query, insert, update, and delete data.
42. What are the differences between DDL, DML, and DCL in SQL?
• DDL (Data Definition Language): Deals with the structure of the database (e.g.,
CREATE, ALTER, DROP).
• DML (Data Manipulation Language): Deals with the manipulation of data (e.g.,
SELECT, INSERT, UPDATE, DELETE).
• DCL (Data Control Language): Deals with user permissions and access control
(e.g., GRANT, REVOKE).
43. What is a primary key?
A unique key ensures that all values in a column are different from one another.
Unlike the primary key, a table can have multiple unique keys, and it allows NULL values
(but only one NULL).
A foreign key is a column in a table that links to the primary key in another table.
It creates a relationship between two tables and ensures referential integrity.
A join is used to combine rows from two or more tables based on a related column between
them.
It helps to retrieve data from multiple tables in a single query.
• INNER JOIN: Returns records that have matching values in both tables.
• LEFT JOIN (or LEFT OUTER JOIN): Returns all records from the left table, and
matching records from the right table.
• RIGHT JOIN (or RIGHT OUTER JOIN): Returns all records from the right table,
and matching records from the left table.
• FULL JOIN (or FULL OUTER JOIN): Returns all records when there is a match in
either left or right table.
A cross join returns the Cartesian product of two tables, meaning it combines each row from
the first table with every row from the second table.
It may result in a large number of rows if tables have many records.
• 1NF (First Normal Form): Ensures each column contains atomic values and rows
are unique.
• 2NF (Second Normal Form): Achieved by removing partial dependency (non-prime
attributes depend on whole primary key).
• 3NF (Third Normal Form): Removes transitive dependency, ensuring that non-
prime attributes depend only on the primary key.
• BCNF (Boyce-Codd Normal Form): A stricter version of 3NF, where every
determinant is a candidate key.
An index is a database object that improves the speed of data retrieval operations on a table.
It creates a quick lookup mechanism for faster search performance.
• Atomicity: Ensures all operations in a transaction are completed; otherwise, none are.
• Consistency: Ensures the database moves from one valid state to another.
• Isolation: Ensures that transactions are executed independently without interference.
• Durability: Ensures that once a transaction is committed, it is permanent, even in the
case of a system crash.
SQL EXAMPLE
57. How to select unique records from a table?
This query returns only unique records from a specified column in a table.
58. What is the command used to fetch the first 5 characters of the string?
The SUBSTRING function is used to extract the first 5 characters from the column.
59. Write an SQL query to find the names of employees that start with ‘A’?
This query uses the LIKE operator to match names starting with 'A'.
60. Query to find the 2nd highest salary of an employee?
This subquery finds the maximum salary below the highest salary, thus giving the second
highest.
61. Write a SQL query to fetch the count of employees working in project 'P1'.
62. Write a SQL query to fetch employee names having salary greater than or equal
to 5000 and less than or equal 10000.
SELECT FullName FROM EmployeeSalary WHERE Salary BETWEEN 5000 AND 10000;
This query fetches employee names with salaries between 5000 and 10000.
63. Write a SQL query to fetch project-wise count of employees sorted by project's
count in descending order.
This query groups employees by their project and counts them, sorting by the count in
descending order.
64. Write a query to fetch only the first name (string before space) from the
FullName column of EmployeeDetails table.
The SUBSTRING and CHARINDEX functions extract the first name by finding the position
of the space.
65. Write a query to fetch employee names and salary records. Return employee
details even if the salary record is not present for the employee.
This query uses a LEFT JOIN to fetch all employee details, even if salary data is absent.
66. Write a SQL query to fetch all the Employees who are also managers from
EmployeeDetails table.
This query selects employees whose EmpId is listed as a ManagerId in the table.
67. Write a SQL query to fetch all employee records from EmployeeDetails table
who have a salary record in EmployeeSalary table.
This query fetches employees who have a corresponding salary record in the EmployeeSalary
table.
This query returns all values that appear more than once in a specific column.
69. Write a SQL query to remove duplicates from a table without using a temporary
table.
This query deletes duplicate rows by keeping the first occurrence and removing others.
70. Write a SQL query to fetch only odd rows from a table.
This query uses ROWNUM to filter and return only odd-numbered rows.
71. Write a SQL query to fetch only even rows from a table.
This query uses ROWNUM to filter and return only even-numbered rows.
72. Write a SQL query to create a new table with data and structure copied from
another table.
This query creates a new table with the same data and structure as an existing table.
73. Write a SQL query to create an empty table with the same structure as another
table.
This query creates an empty table with the same structure as the existing table, but without
any data.
74. Write a SQL query to fetch common records between two tables.
This query fetches records that are present in both tables based on a matching column.
75. Write a SQL query to fetch records that are present in one table but not in
another table.
This query selects records from table1 that are not present in table2.
76. Write SQL query to find the 3rd highest salary from table without using
TOP/limit keyword.
This query uses a subquery to first find the top 3 salaries, then selects the minimum of those,
giving the 3rd highest salary.