[go: up one dir, main page]

0% found this document useful (0 votes)
31 views13 pages

NIMAP INTERVIEW

The document provides a comprehensive overview of Java programming concepts, including methods for swapping numbers, features of Java, object-oriented principles like inheritance, encapsulation, and polymorphism, as well as SQL fundamentals such as DDL, DML, and various types of joins. It also covers exception handling, ACID properties, normalization, and practical SQL queries for data manipulation. Overall, it serves as a guide for understanding key programming and database concepts.

Uploaded by

rahulbhoir590
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views13 pages

NIMAP INTERVIEW

The document provides a comprehensive overview of Java programming concepts, including methods for swapping numbers, features of Java, object-oriented principles like inheritance, encapsulation, and polymorphism, as well as SQL fundamentals such as DDL, DML, and various types of joins. It also covers exception handling, ACID properties, normalization, and practical SQL queries for data manipulation. Overall, it serves as a guide for understanding key programming and database concepts.

Uploaded by

rahulbhoir590
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

NIMAP INTERVIEW

1. How to swap two numbers using a temporary variable?


We use a temporary variable to hold one of the values.
int a = 10, b = 20;
int temp = a; a = b; b = temp;
This swaps the values of a and b safely.

2. How to swap two numbers without using a temporary variable?


We can use arithmetic operations:
a = a + b; b = a - b; a = a - b;
This swaps two values without extra memory.

3. What are the features in Java?


Java is simple, object-oriented, platform-independent, and secure.
It supports multithreading, is robust due to strong memory management, and has automatic
garbage collection.

4. What do you mean by Constructor?


A constructor is a special method used to initialize objects.
It has the same name as the class and no return type, and it's called automatically when an
object is created.

5. What is meant by Local variable and Instance variable?


A local variable is declared inside a method and exists only during method execution.
An instance variable is declared inside a class but outside methods and belongs to each object
instance.

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).

9. What is meant by Method Overriding?


Overriding means redefining a method of a parent class in the child class using the same
signature.
It is used for runtime polymorphism and dynamic method dispatch.

10. What is meant by Overloading?


Method overloading means having multiple methods with the same name but different
parameters.
It is resolved at compile-time and increases code flexibility.

11. What is meant by Interface?


An interface in Java is a reference type used to achieve abstraction and multiple inheritance.
It contains only abstract methods (till Java 7), and implementing classes must define those
methods.

12. What is meant by Abstract class?


An abstract class is a class that cannot be instantiated and may contain abstract and non-
abstract methods.
It’s used when we want to provide partial implementation to subclasses.

13. Difference between Array and ArrayList?


An Array is a fixed-size data structure that holds elements of the same type.
ArrayList is part of the Collection framework, resizable, and allows dynamic memory
allocation.
14. What is the meaning of “IS-A” and “HAS-A” relationship?
IS-A represents inheritance (e.g., Dog IS-A Animal).
HAS-A represents composition (e.g., Car HAS-A Engine).

15. Can you explain the different types of Inheritance?


• Single: One class inherits from one class.
• Multilevel: Class inherits from a class, which inherits from another.
• Hierarchical: Multiple classes inherit from one parent class.
(Java doesn't support multiple inheritance with classes.)

16. Explain Access Specifiers in Java.


Java has four access specifiers:
• Public: Accessible everywhere
• Private: Only within the class
• Protected: Within package and subclasses
• Default: Within the same package

17. Explain about Public and Private access specifiers.


Public members are accessible from anywhere.
Private members are accessible only within the declared class.

18. Difference between Default and Protected access specifiers.


Default: Accessible only within the same package.
Protected: Accessible within the same package and also by subclasses outside the package.

19. Difference between Abstract class and Interface.


• Abstract class can have constructors and both abstract/non-abstract methods.
• Interface cannot have constructors and supports only abstract methods (until Java 8).
Interfaces support multiple inheritance; abstract classes do not.

20. What is meant by Collections in Java?


Collections in Java is a framework that provides architecture to store and manipulate groups
of objects.
It includes interfaces like List, Set, Map and classes like ArrayList, HashSet, HashMap.
21. What is meant by Exception?
An exception is an unwanted or unexpected event that disrupts the normal flow of a program.
Java provides a robust exception handling mechanism using try-catch blocks.

22. What are the types of Exceptions?


• Checked exceptions: Checked at compile-time (e.g., IOException).
• Unchecked exceptions: Checked at runtime (e.g., NullPointerException).

23. What are the different ways to handle exceptions?


We can handle exceptions using try-catch, try-catch-finally, or throws keyword.
The finally block is always executed, used for cleanup code.

24. What is the final keyword in Java?


The final keyword is used to declare constants, prevent method overriding, and inheritance.
• Final variable → constant
• Final method → can't be overridden
• Final class → can't be extended

25. What is a Thread?


A thread is a lightweight subprocess, the smallest unit of execution.
Java supports multithreading using the Thread class or Runnable interface.

26. Sorting Algorithms:


Sorting algorithms are used to arrange data in a specific order (ascending/descending).
Common ones include Bubble Sort, Selection Sort, Insertion Sort, Merge Sort, etc.

27. Bubble Sort:


Compares adjacent elements and swaps them if they're in the wrong order.
Time complexity: O(n²) in worst case.

28. Selection Sort:


Finds the minimum element and places it at the beginning in each pass.
Time complexity: O(n²); works well for small datasets.
29. Insertion Sort:
Builds the final sorted array one item at a time by comparing with previous elements.
Best case: O(n) (when nearly sorted); worst: O(n²).

30. Merge Sort:


A divide-and-conquer algorithm that splits the array, sorts recursively, and merges them.
Time complexity: O(n log n) in all cases. Very efficient for large datasets.

31. Object manipulation - OOP:


Object manipulation refers to creating, accessing, and modifying object properties and
methods using Object-Oriented Programming principles like encapsulation, inheritance, and
polymorphism.

32. Searching algorithms:


Searching algorithms help locate elements in a data structure.
Common ones include Linear Search (O(n)) and Binary Search (O(log n)) for sorted
arrays.

33. Space and Time Complexity:


Time complexity shows how long an algorithm takes based on input size (n).
Space complexity shows how much memory it uses. Both help in optimizing code.

34. Big-O Notation:


Big-O represents the worst-case time or space complexity of an algorithm.
Examples: O(1) → constant, O(n) → linear, O(n²) → quadratic.

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)).

36. How web request works (DNS - IP):


When a user types a URL, the browser queries DNS to get the IP address.
Then, it sends an HTTP request to the server via that IP to fetch and render the content.

37. What is Overloading and Overriding?


Overloading: Same method name, different parameters (compile-time).
Overriding: Redefining a superclass method in a subclass (runtime).

38. What is an Abstract Class?


An abstract class cannot be instantiated and may contain abstract and regular methods.
It’s used to define common behavior for subclasses.

39. Difference between continue and break statement:


continue skips the current loop iteration and goes to the next.
break exits the loop completely.

40. What is ternary operator? Give an example:


The ternary operator is a shortcut for if-else:
java
int a = 10, b = 20;
int max = (a > b) ? a : b;
It returns one of two values based on a condition.

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 primary key is a unique identifier for a record in a table.


It ensures that each record is unique and cannot be NULL.

44. What is a unique 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).

45. What is a foreign key?

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.

46. What is a join?

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.

47. What are the types of join and explain each?

• 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.

48. What is Self-Join?

A self-join is a join where a table is joined with itself.


It is useful when comparing rows within the same table (e.g., employees and their managers).
49. What is Cross-Join?

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.

50. What is normalization?

Normalization is the process of organizing data in a database to reduce redundancy and


dependency.
It divides large tables into smaller tables and defines relationships between them.

51. What is Denormalization?

Denormalization is the process of intentionally introducing redundancy by combining tables.


It is used to improve read performance at the cost of data integrity and update efficiency.

52. What are all the different normalizations?

The primary normal forms are:

• 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.

53. What is a View?

A view is a virtual table based on the result of a query.


It does not store data physically but can simplify complex queries by presenting them as a
table.
54. What is an Index?

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.

55. What are all the different types of indexes?

• Unique Index: Ensures that all values in a column are unique.


• Composite Index: An index on multiple columns.
• Clustered Index: Data is stored in the index order, and a table can have only one.
• Non-clustered Index: Index is stored separately, and a table can have multiple non-
clustered indexes.

56. ACID properties

ACID stands for:

• 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?

SELECT DISTINCT column_name FROM table_name;

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?

SELECT SUBSTRING(column_name, 1, 5) FROM table_name;

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’?

SELECT FullName FROM EmployeeDetails WHERE FullName LIKE 'A%';

This query uses the LIKE operator to match names starting with 'A'.
60. Query to find the 2nd highest salary of an employee?

SELECT MAX(Salary) FROM EmployeeSalary WHERE Salary < (SELECT MAX(Salary)


FROM EmployeeSalary);

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'.

SELECT COUNT(*) FROM EmployeeSalary WHERE Project = 'P1';

This query counts the number of employees working on 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.

SELECT Project, COUNT(*) AS EmployeeCount FROM EmployeeSalary GROUP BY


Project ORDER BY EmployeeCount DESC;

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.

SELECT SUBSTRING(FullName, 1, CHARINDEX(' ', FullName) - 1) AS FirstName


FROM EmployeeDetails;

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.

SELECT e.FullName, s.Salary FROM EmployeeDetails e LEFT JOIN EmployeeSalary s ON


e.EmpId = s.EmpId;

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.

SELECT e.FullName FROM EmployeeDetails e WHERE e.EmpId IN (SELECT DISTINCT


ManagerId FROM EmployeeDetails);

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.

SELECT e.* FROM EmployeeDetails e INNER JOIN EmployeeSalary s ON e.EmpId =


s.EmpId;

This query fetches employees who have a corresponding salary record in the EmployeeSalary
table.

68. Write a SQL query to fetch duplicate records from a table.

SELECT column_name, COUNT(*) FROM table_name GROUP BY column_name


HAVING COUNT(*) > 1;

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.

DELETE FROM table_name WHERE rowid NOT IN (SELECT MIN(rowid) FROM


table_name GROUP BY column_name);

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.

SELECT * FROM table_name WHERE MOD(ROWNUM, 2) = 1;

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.

SELECT * FROM table_name WHERE MOD(ROWNUM, 2) = 0;

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.

CREATE TABLE new_table AS SELECT * FROM old_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.

CREATE TABLE new_table LIKE old_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.

SELECT * FROM table1 WHERE EXISTS (SELECT 1 FROM table2 WHERE


table1.column_name = table2.column_name);

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.

SELECT * FROM table1 WHERE column_name NOT IN (SELECT column_name FROM


table2);

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.

SELECT MIN(Salary) FROM (SELECT DISTINCT Salary FROM EmployeeSalary ORDER


BY Salary DESC LIMIT 3) AS temp;

This query uses a subquery to first find the top 3 salaries, then selects the minimum of those,
giving the 3rd highest salary.

You might also like