Experion Technologies - Complete Technical Interview Guide
Table of Contents
Comprehensive Study Guide for Technical Interviews
Table of Contents
Object-Oriented Programming (OOP)
Core OOP Concepts
Data Structures & Algorithms (DSA)
Basic Data Structures
Advanced Data Structures
Sorting Algorithms
SQL & Database Management
Basic SQL Concepts
Java Programming Concepts
Core Java Fundamentals
Interview Questions by Category
Object-Oriented Programming Interview Questions
Data Structures & Algorithms Interview Questions
SQL Interview Questions
Java Programming Interview Questions
Tips for Technical Interview Success
Comprehensive Study Guide for Technical Interviews
Covering: Object-Oriented Programming (OOP), Data Structures & Algorithms (DSA), SQL & Database Management, Java
Programming Concepts
Table of Contents
1. Object-Oriented Programming (OOP)
2. Data Structures & Algorithms (DSA)
3. SQL & Database Management
4. Java Programming Concepts
5. Interview Questions by Category
Object-Oriented Programming (OOP)
Core OOP Concepts
1. Classes and Objects
Class: A blueprint or template that defines the properties and behaviors of objects.
Object: An instance of a class that contains actual data and can perform actions.
// Class definition
public class Car {
// Properties (attributes)
private String brand;
private String model;
private int year;
// Constructor
public Car(String brand, String model, int year) {
[Link] = brand;
[Link] = model;
[Link] = year;
}
// Methods (behaviors)
public void start() {
[Link]("Car is starting...");
}
public void displayInfo() {
[Link](year + " " + brand + " " + model);
}
}
// Object creation
Car myCar = new Car("Toyota", "Camry", 2022);
[Link]();
[Link]();
Key Points:
Objects have state (attributes) and behavior (methods)
Classes define the structure, objects contain the actual data
Objects are created using the new keyword in Java
2. Encapsulation
Definition: The bundling of data and methods that operate on that data within a single unit (class), and restricting direct access to
some components.
Benefits:
Data hiding and security
Better maintainability
Controlled access through getter/setter methods
public class BankAccount {
private double balance; // Private - encapsulated data
private String accountNumber;
// Constructor
public BankAccount(String accountNumber, double initialBalance) {
[Link] = accountNumber;
[Link] = initialBalance;
}
// Getter method (controlled access)
public double getBalance() {
return balance;
}
// Setter method with validation
public void deposit(double amount) {
if (amount > 0) {
balance += amount;
} else {
[Link]("Invalid deposit amount");
}
}
public void withdraw(double amount) {
if (amount > 0 && amount <= balance) {
balance -= amount;
} else {
[Link]("Invalid withdrawal amount");
}
}
}
3. Inheritance
Definition: A mechanism that allows a new class to acquire properties and methods of an existing class.
Types of Inheritance:
Single Inheritance: One subclass inherits from one superclass
Multilevel Inheritance: Chain of inheritance (A → B → C)
Hierarchical Inheritance: Multiple subclasses inherit from one superclass
Multiple Inheritance: Not supported in Java (through classes)
// Parent class (Superclass)
public class Vehicle {
protected String brand;
protected int year;
public Vehicle(String brand, int year) {
[Link] = brand;
[Link] = year;
}
public void start() {
[Link]("Vehicle is starting...");
}
public void displayInfo() {
[Link](year + " " + brand);
}
}
// Child class (Subclass)
public class Car extends Vehicle {
private int doors;
public Car(String brand, int year, int doors) {
super(brand, year); // Call parent constructor
[Link] = doors;
}
// Method overriding
@Override
public void start() {
[Link]("Car engine is starting...");
}
// Additional method
public void honk() {
[Link]("Car is honking!");
}
}
// Usage
Car myCar = new Car("Honda", 2021, 4);
[Link](); // Calls overridden method
[Link](); // Inherited method
[Link](); // Car-specific method
4. Polymorphism
Definition: The ability of objects of different classes to be treated as objects of a common base class, while each maintains its own
specific behavior.
Types:
1. Compile-time Polymorphism (Method Overloading)
2. Runtime Polymorphism (Method Overriding)
Method Overloading Example:
public class Calculator {
// Same method name, different parameters
public int add(int a, int b) {
return a + b;
}
public double add(double a, double b) {
return a + b;
}
public int add(int a, int b, int c) {
return a + b + c;
}
}
Method Overriding Example:
// Parent class
abstract class Animal {
public abstract void makeSound();
public void sleep() {
[Link]("Animal is sleeping");
}
}
// Child classes
class Dog extends Animal {
@Override
public void makeSound() {
[Link]("Dog barks: Woof!");
}
}
class Cat extends Animal {
@Override
public void makeSound() {
[Link]("Cat meows: Meow!");
}
}
// Polymorphism in action
Animal[] animals = {new Dog(), new Cat()};
for (Animal animal : animals) {
[Link](); // Different behavior based on actual object type
}
5. Abstraction
Definition: Hiding complex implementation details while showing only essential features of an object.
Achieved through:
1. Abstract Classes
2. Interfaces
Abstract Class Example:
abstract class Shape {
protected String color;
public Shape(String color) {
[Link] = color;
}
// Abstract method - must be implemented by subclasses
public abstract double calculateArea();
// Concrete method - can be inherited as-is
public void displayColor() {
[Link]("Shape color: " + color);
}
}
class Circle extends Shape {
private double radius;
public Circle(String color, double radius) {
super(color);
[Link] = radius;
}
@Override
public double calculateArea() {
return [Link] * radius * radius;
}
}
class Rectangle extends Shape {
private double length, width;
public Rectangle(String color, double length, double width) {
super(color);
[Link] = length;
[Link] = width;
}
@Override
public double calculateArea() {
return length * width;
}
}
Interface Example:
interface Drawable {
void draw(); // Public and abstract by default
// Default method (Java 8+)
default void print() {
[Link]("Printing...");
}
// Static method (Java 8+)
static void info() {
[Link]("Drawable interface");
}
}
class Square implements Drawable {
@Override
public void draw() {
[Link]("Drawing a square");
}
}
6. Access Modifiers
Modifier Class Package Subclass World
public ✓ ✓ ✓ ✓
protected ✓ ✓ ✓ ✗
default ✓ ✓ ✗ ✗
private ✓ ✗ ✗ ✗
Data Structures & Algorithms (DSA)
Basic Data Structures
1. Arrays
Definition: A collection of elements stored at contiguous memory locations.
Characteristics:
Fixed size
Random access (O(1))
Elements of same data type
Common Operations:
// Array declaration and initialization
int[] numbers = {1, 2, 3, 4, 5};
int[] arr = new int[10]; // Array of size 10
// Access elements
int first = numbers[0]; // O(1)
// Update elements
numbers[2] = 10; // O(1)
// Search element (Linear Search)
public static int linearSearch(int[] arr, int target) {
for (int i = 0; i < [Link]; i++) {
if (arr[i] == target) {
return i; // Return index
}
}
return -1; // Not found
}
// Binary Search (for sorted arrays)
public static int binarySearch(int[] arr, int target) {
int left = 0, right = [Link] - 1;
while (left <= right) {
int mid = left + (right - left) / 2;
if (arr[mid] == target) {
return mid;
} else if (arr[mid] < target) {
left = mid + 1;
} else {
right = mid - 1;
}
}
return -1; // Not found
}
Advantages:
Fast random access
Cache-friendly
Simple to use
Disadvantages:
Fixed size
Expensive insertion/deletion
Memory wastage if not fully utilized
2. Linked Lists
Definition: A linear data structure where elements are stored in nodes, and each node contains data and a reference to the next
node.
Types:
Singly Linked List
Doubly Linked List
Circular Linked List
Singly Linked List Implementation:
class ListNode {
int data;
ListNode next;
public ListNode(int data) {
[Link] = data;
[Link] = null;
}
}
class LinkedList {
private ListNode head;
// Insert at beginning
public void insertAtBeginning(int data) {
ListNode newNode = new ListNode(data);
[Link] = head;
head = newNode;
}
// Insert at end
public void insertAtEnd(int data) {
ListNode newNode = new ListNode(data);
if (head == null) {
head = newNode;
return;
}
ListNode current = head;
while ([Link] != null) {
current = [Link];
}
[Link] = newNode;
}
// Delete a node
public void delete(int data) {
if (head == null) return;
if ([Link] == data) {
head = [Link];
return;
}
ListNode current = head;
while ([Link] != null && [Link] != data) {
current = [Link];
}
if ([Link] != null) {
[Link] = [Link];
}
}
// Display the list
public void display() {
ListNode current = head;
while (current != null) {
[Link]([Link] + " -> ");
current = [Link];
}
[Link]("null");
}
// Reverse the linked list
public void reverse() {
ListNode prev = null;
ListNode current = head;
ListNode next = null;
while (current != null) {
next = [Link];
[Link] = prev;
prev = current;
current = next;
}
head = prev;
}
}
Advantages:
Dynamic size
Efficient insertion/deletion at beginning
Memory efficient (allocates as needed)
Disadvantages:
No random access
Extra memory for pointers
Not cache-friendly
3. Stacks
Definition: A linear data structure that follows Last In First Out (LIFO) principle.
Operations:
Push: Add element to top
Pop: Remove element from top
Peek/Top: View top element without removing
isEmpty: Check if stack is empty
Implementation using Array:
class Stack {
private int[] arr;
private int top;
private int capacity;
public Stack(int size) {
arr = new int[size];
capacity = size;
top = -1;
}
public void push(int item) {
if (top == capacity - 1) {
[Link]("Stack Overflow");
return;
}
arr[++top] = item;
}
public int pop() {
if (isEmpty()) {
[Link]("Stack Underflow");
return -1;
}
return arr[top--];
}
public int peek() {
if (isEmpty()) {
[Link]("Stack is empty");
return -1;
}
return arr[top];
}
public boolean isEmpty() {
return top == -1;
}
public int size() {
return top + 1;
}
}
Applications:
Function call management
Expression evaluation
Undo operations
Browser back button
Parentheses matching
4. Queues
Definition: A linear data structure that follows First In First Out (FIFO) principle.
Operations:
Enqueue: Add element to rear
Dequeue: Remove element from front
Front: View front element
Rear: View rear element
isEmpty: Check if queue is empty
Implementation using Array:
class Queue {
private int[] arr;
private int front, rear, size, capacity;
public Queue(int capacity) {
[Link] = capacity;
arr = new int[capacity];
front = 0;
rear = -1;
size = 0;
}
public void enqueue(int item) {
if (size == capacity) {
[Link]("Queue is full");
return;
}
rear = (rear + 1) % capacity;
arr[rear] = item;
size++;
}
public int dequeue() {
if (isEmpty()) {
[Link]("Queue is empty");
return -1;
}
int item = arr[front];
front = (front + 1) % capacity;
size--;
return item;
}
public int front() {
if (isEmpty()) {
[Link]("Queue is empty");
return -1;
}
return arr[front];
}
public boolean isEmpty() {
return size == 0;
}
public int size() {
return size;
}
}
Applications:
Process scheduling
Breadth-first search
Print queue management
Handling requests in web servers
Advanced Data Structures
1. Trees
Definition: A hierarchical data structure with nodes connected by edges, having a root node and no cycles.
Binary Tree Properties:
Each node has at most two children (left and right)
Root node has no parent
Leaf nodes have no children
Binary Tree Implementation:
class TreeNode {
int data;
TreeNode left, right;
public TreeNode(int data) {
[Link] = data;
left = right = null;
}
}
class BinaryTree {
TreeNode root;
// Tree Traversals
// Inorder: Left -> Root -> Right
public void inorder(TreeNode node) {
if (node != null) {
inorder([Link]);
[Link]([Link] + " ");
inorder([Link]);
}
}
// Preorder: Root -> Left -> Right
public void preorder(TreeNode node) {
if (node != null) {
[Link]([Link] + " ");
preorder([Link]);
preorder([Link]);
}
}
// Postorder: Left -> Right -> Root
public void postorder(TreeNode node) {
if (node != null) {
postorder([Link]);
postorder([Link]);
[Link]([Link] + " ");
}
}
// Height of tree
public int height(TreeNode node) {
if (node == null) {
return -1;
}
return 1 + [Link](height([Link]), height([Link]));
}
// Level order traversal (BFS)
public void levelOrder() {
if (root == null) return;
Queue<TreeNode> queue = new LinkedList<>();
[Link](root);
while (![Link]()) {
TreeNode current = [Link]();
[Link]([Link] + " ");
if ([Link] != null) {
[Link]([Link]);
}
if ([Link] != null) {
[Link]([Link]);
}
}
}
}
2. Binary Search Tree (BST)
Properties:
Left subtree contains nodes with values less than root
Right subtree contains nodes with values greater than root
Both subtrees are also BSTs
class BST {
TreeNode root;
// Insert operation
public TreeNode insert(TreeNode root, int data) {
if (root == null) {
return new TreeNode(data);
}
if (data < [Link]) {
[Link] = insert([Link], data);
} else if (data > [Link]) {
[Link] = insert([Link], data);
}
return root;
}
// Search operation
public boolean search(TreeNode root, int data) {
if (root == null) {
return false;
}
if (data == [Link]) {
return true;
} else if (data < [Link]) {
return search([Link], data);
} else {
return search([Link], data);
}
}
// Find minimum value node
public TreeNode findMin(TreeNode root) {
while (root != null && [Link] != null) {
root = [Link];
}
return root;
}
// Delete operation
public TreeNode delete(TreeNode root, int data) {
if (root == null) {
return root;
}
if (data < [Link]) {
[Link] = delete([Link], data);
} else if (data > [Link]) {
[Link] = delete([Link], data);
} else {
// Node to be deleted found
// Case 1: Node has no children
if ([Link] == null && [Link] == null) {
return null;
}
// Case 2: Node has one child
else if ([Link] == null) {
return [Link];
} else if ([Link] == null) {
return [Link];
}
// Case 3: Node has two children
else {
TreeNode temp = findMin([Link]);
[Link] = [Link];
[Link] = delete([Link], [Link]);
}
}
return root;
}
}
3. Hash Tables
Definition: A data structure that implements an associative array abstract data type, mapping keys to values using a hash function.
class HashTable<K, V> {
private static class Entry<K, V> {
K key;
V value;
Entry<K, V> next;
Entry(K key, V value) {
[Link] = key;
[Link] = value;
}
}
private Entry<K, V>[] table;
private int size;
private int capacity;
@SuppressWarnings("unchecked")
public HashTable(int capacity) {
[Link] = capacity;
[Link] = new Entry[capacity];
[Link] = 0;
}
private int hash(K key) {
return [Link]([Link]() % capacity);
}
public void put(K key, V value) {
int index = hash(key);
Entry<K, V> entry = table[index];
// Check if key already exists
while (entry != null) {
if ([Link](key)) {
[Link] = value; // Update existing
return;
}
entry = [Link];
}
// Add new entry at beginning of chain
Entry<K, V> newEntry = new Entry<>(key, value);
[Link] = table[index];
table[index] = newEntry;
size++;
}
public V get(K key) {
int index = hash(key);
Entry<K, V> entry = table[index];
while (entry != null) {
if ([Link](key)) {
return [Link];
}
entry = [Link];
}
return null; // Key not found
}
public V remove(K key) {
int index = hash(key);
Entry<K, V> entry = table[index];
Entry<K, V> prev = null;
while (entry != null) {
if ([Link](key)) {
if (prev == null) {
table[index] = [Link];
} else {
[Link] = [Link];
}
size--;
return [Link];
}
prev = entry;
entry = [Link];
}
return null; // Key not found
}
}
Sorting Algorithms
1. Bubble Sort
public static void bubbleSort(int[] arr) {
int n = [Link];
for (int i = 0; i < n - 1; i++) {
boolean swapped = false;
for (int j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
// Swap elements
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
swapped = true;
}
}
if (!swapped) break; // Already sorted
}
}
// Time Complexity: O(n²), Space Complexity: O(1)
2. Selection Sort
public static void selectionSort(int[] arr) {
int n = [Link];
for (int i = 0; i < n - 1; i++) {
int minIndex = i;
for (int j = i + 1; j < n; j++) {
if (arr[j] < arr[minIndex]) {
minIndex = j;
}
}
// Swap minimum element with first element
int temp = arr[minIndex];
arr[minIndex] = arr[i];
arr[i] = temp;
}
}
// Time Complexity: O(n²), Space Complexity: O(1)
3. Merge Sort
public static void mergeSort(int[] arr, int left, int right) {
if (left < right) {
int mid = left + (right - left) / 2;
mergeSort(arr, left, mid);
mergeSort(arr, mid + 1, right);
merge(arr, left, mid, right);
}
}
private static void merge(int[] arr, int left, int mid, int right) {
int[] leftArray = new int[mid - left + 1];
int[] rightArray = new int[right - mid];
[Link](arr, left, leftArray, 0, [Link]);
[Link](arr, mid + 1, rightArray, 0, [Link]);
int i = 0, j = 0, k = left;
while (i < [Link] && j < [Link]) {
if (leftArray[i] <= rightArray[j]) {
arr[k++] = leftArray[i++];
} else {
arr[k++] = rightArray[j++];
}
}
while (i < [Link]) {
arr[k++] = leftArray[i++];
}
while (j < [Link]) {
arr[k++] = rightArray[j++];
}
}
// Time Complexity: O(n log n), Space Complexity: O(n)
SQL & Database Management
Basic SQL Concepts
1. SQL Commands Categories
DDL (Data Definition Language):
CREATE - Create database objects
ALTER - Modify database objects
DROP - Delete database objects
TRUNCATE - Remove all records from table
DML (Data Manipulation Language):
SELECT - Retrieve data
INSERT - Add new records
UPDATE - Modify existing records
DELETE - Remove records
DCL (Data Control Language):
GRANT - Give permissions
REVOKE - Remove permissions
TCL (Transaction Control Language):
COMMIT - Save changes permanently
ROLLBACK - Undo changes
SAVEPOINT - Set save points
2. Basic SQL Queries
Creating and Using Database:
-- Create database
CREATE DATABASE CompanyDB;
-- Use database
USE CompanyDB;
-- Create table
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
FirstName VARCHAR(50) NOT NULL,
LastName VARCHAR(50) NOT NULL,
Email VARCHAR(100) UNIQUE,
Department VARCHAR(50),
Salary DECIMAL(10,2),
HireDate DATE,
ManagerID INT,
FOREIGN KEY (ManagerID) REFERENCES Employees(EmployeeID)
);
-- Insert data
INSERT INTO Employees VALUES
(1, 'John', 'Doe', '[Link]@[Link]', 'IT', 75000.00, '2022-01-15', NULL),
(2, 'Jane', 'Smith', '[Link]@[Link]', 'HR', 65000.00, '2022-02-20', 1),
(3, 'Mike', 'Johnson', '[Link]@[Link]', 'IT', 70000.00, '2022-03-10', 1),
(4, 'Sarah', 'Wilson', '[Link]@[Link]', 'Finance', 80000.00, '2022-01-25', NULL);
Basic SELECT Queries:
-- Select all columns
SELECT * FROM Employees;
-- Select specific columns
SELECT FirstName, LastName, Salary FROM Employees;
-- Select with condition
SELECT * FROM Employees WHERE Department = 'IT';
-- Select with multiple conditions
SELECT * FROM Employees
WHERE Department = 'IT' AND Salary > 70000;
-- Select with range
SELECT * FROM Employees
WHERE Salary BETWEEN 60000 AND 80000;
-- Select with pattern matching
SELECT * FROM Employees
WHERE Email LIKE '%@[Link]';
-- Select with sorting
SELECT * FROM Employees
ORDER BY Salary DESC;
-- Select top records
SELECT * FROM Employees
LIMIT 5;
3. Aggregate Functions
-- Count records
SELECT COUNT(*) FROM Employees;
-- Count non-null values
SELECT COUNT(ManagerID) FROM Employees;
-- Sum of salaries
SELECT SUM(Salary) FROM Employees;
-- Average salary
SELECT AVG(Salary) FROM Employees;
-- Maximum and minimum salary
SELECT MAX(Salary), MIN(Salary) FROM Employees;
-- Group by department
SELECT Department, COUNT(*) as EmployeeCount, AVG(Salary) as AvgSalary
FROM Employees
GROUP BY Department;
-- Group by with condition
SELECT Department, COUNT(*) as EmployeeCount
FROM Employees
GROUP BY Department
HAVING COUNT(*) > 1;
4. SQL JOINS
Types of Joins:
INNER JOIN - Returns matching records from both tables:
SELECT [Link], [Link], [Link]
FROM Employees e
INNER JOIN Departments d ON [Link] = [Link];
LEFT JOIN - Returns all records from left table and matching from right:
SELECT [Link], [Link], [Link]
FROM Employees e
LEFT JOIN Departments d ON [Link] = [Link];
RIGHT JOIN - Returns all records from right table and matching from left:
SELECT [Link], [Link], [Link]
FROM Employees e
RIGHT JOIN Departments d ON [Link] = [Link];
FULL OUTER JOIN - Returns all records from both tables:
SELECT [Link], [Link], [Link]
FROM Employees e
FULL OUTER JOIN Departments d ON [Link] = [Link];
SELF JOIN - Join table with itself:
SELECT [Link] + ' ' + [Link] as Employee,
[Link] + ' ' + [Link] as Manager
FROM Employees e1
LEFT JOIN Employees e2 ON [Link] = [Link];
5. Subqueries
Single Value Subquery:
-- Find employees earning more than average salary
SELECT FirstName, LastName, Salary
FROM Employees
WHERE Salary > (SELECT AVG(Salary) FROM Employees);
Multiple Value Subquery:
-- Find employees in departments with more than 2 employees
SELECT FirstName, LastName, Department
FROM Employees
WHERE Department IN (
SELECT Department
FROM Employees
GROUP BY Department
HAVING COUNT(*) > 2
);
Correlated Subquery:
-- Find employees earning more than average in their department
SELECT [Link], [Link], [Link], [Link]
FROM Employees e1
WHERE [Link] > (
SELECT AVG([Link])
FROM Employees e2
WHERE [Link] = [Link]
);
EXISTS Subquery:
-- Find departments that have employees
SELECT DISTINCT Department
FROM Employees e1
WHERE EXISTS (
SELECT 1
FROM Employees e2
WHERE [Link] = [Link]
);
6. Database Normalization
Purpose: Organize database to reduce redundancy and dependency.
Normal Forms:
First Normal Form (1NF):
Each column contains atomic (indivisible) values
Each column has a unique name
Order of data storage doesn't matter
Second Normal Form (2NF):
Must be in 1NF
All non-key attributes must be fully functionally dependent on the primary key
No partial dependency
Third Normal Form (3NF):
Must be in 2NF
No transitive dependency (non-key attributes should not depend on other non-key attributes)
Example of Normalization:
Unnormalized Table:
StudentCourses (StudentID, StudentName, CourseID, CourseName, InstructorID, InstructorName)
After 1NF:
Same structure but ensure atomic values
After 2NF:
Students (StudentID, StudentName)
Courses (CourseID, CourseName, InstructorID, InstructorName)
Enrollments (StudentID, CourseID)
After 3NF:
Students (StudentID, StudentName)
Instructors (InstructorID, InstructorName)
Courses (CourseID, CourseName, InstructorID)
Enrollments (StudentID, CourseID)
7. Indexes
Definition: Database objects that improve query performance by creating shortcuts to data.
-- Create index
CREATE INDEX idx_employee_department ON Employees(Department);
-- Create composite index
CREATE INDEX idx_employee_dept_salary ON Employees(Department, Salary);
-- Create unique index
CREATE UNIQUE INDEX idx_employee_email ON Employees(Email);
-- Drop index
DROP INDEX idx_employee_department;
Types of Indexes:
Clustered Index: Physically reorders table data
Non-Clustered Index: Points to data rows
Unique Index: Ensures uniqueness
Composite Index: Multiple columns
8. Triggers
Definition: Special procedures that automatically execute in response to database events.
-- Create trigger for audit log
CREATE TRIGGER tr_employee_audit
AFTER INSERT, UPDATE, DELETE ON Employees
FOR EACH ROW
BEGIN
IF INSERTING THEN
INSERT INTO EmployeeAudit (Action, EmployeeID, ActionDate)
VALUES ('INSERT', [Link], NOW());
ELSEIF UPDATING THEN
INSERT INTO EmployeeAudit (Action, EmployeeID, ActionDate)
VALUES ('UPDATE', [Link], NOW());
ELSEIF DELETING THEN
INSERT INTO EmployeeAudit (Action, EmployeeID, ActionDate)
VALUES ('DELETE', [Link], NOW());
END IF;
END;
9. Stored Procedures
Definition: Precompiled SQL statements stored in the database.
-- Create stored procedure
DELIMITER //
CREATE PROCEDURE GetEmployeesByDepartment(IN dept_name VARCHAR(50))
BEGIN
SELECT FirstName, LastName, Salary
FROM Employees
WHERE Department = dept_name
ORDER BY Salary DESC;
END //
DELIMITER ;
-- Execute stored procedure
CALL GetEmployeesByDepartment('IT');
-- Stored procedure with output parameter
DELIMITER //
CREATE PROCEDURE GetEmployeeCount(IN dept_name VARCHAR(50), OUT emp_count INT)
BEGIN
SELECT COUNT(*) INTO emp_count
FROM Employees
WHERE Department = dept_name;
END //
DELIMITER ;
-- Execute with output
CALL GetEmployeeCount('IT', @count);
SELECT @count;
10. Views
Definition: Virtual tables based on SQL queries.
-- Create view
CREATE VIEW EmployeeDetails AS
SELECT [Link], [Link], [Link], [Link],
[Link], [Link]
FROM Employees e
JOIN Departments d ON [Link] = [Link];
-- Use view
SELECT * FROM EmployeeDetails WHERE Salary > 70000;
-- Update view (if updatable)
UPDATE EmployeeDetails SET Salary = 85000 WHERE EmployeeID = 1;
-- Drop view
DROP VIEW EmployeeDetails;
Java Programming Concepts
Core Java Fundamentals
1. Java Class Structure
// Package declaration
package [Link];
// Import statements
import [Link].*;
import [Link].*;
// Class declaration
public class Employee {
// Instance variables (attributes)
private String name;
private int id;
private double salary;
// Static variable (class variable)
private static int employeeCount = 0;
// Constants
public static final String COMPANY_NAME = "TechCorp";
// Default constructor
public Employee() {
employeeCount++;
}
// Parameterized constructor
public Employee(String name, int id, double salary) {
[Link] = name;
[Link] = id;
[Link] = salary;
employeeCount++;
}
// Copy constructor
public Employee(Employee other) {
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
employeeCount++;
}
// Getter methods
public String getName() {
return name;
}
public int getId() {
return id;
}
public double getSalary() {
return salary;
}
// Setter methods
public void setName(String name) {
[Link] = name;
}
public void setId(int id) {
[Link] = id;
}
public void setSalary(double salary) {
if (salary >= 0) {
[Link] = salary;
}
}
// Static method
public static int getEmployeeCount() {
return employeeCount;
}
// Instance method
public void displayInfo() {
[Link]("ID: " + id + ", Name: " + name + ", Salary: $" + salary);
}
// Method overloading
public void increaseSalary(double amount) {
[Link] += amount;
}
public void increaseSalary(double percentage, boolean isPercentage) {
if (isPercentage) {
[Link] += ([Link] * percentage / 100);
} else {
[Link] += percentage;
}
}
// Override toString method
@Override
public String toString() {
return "Employee{id=" + id + ", name='" + name + "', salary=" + salary + "}";
}
// Override equals method
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != [Link]()) return false;
Employee employee = (Employee) obj;
return id == [Link];
}
// Override hashCode method
@Override
public int hashCode() {
return [Link](id);
}
}
2. Constructor Types and Usage
public class Student {
private String name;
private int age;
private String course;
// Default constructor
public Student() {
[Link] = "Unknown";
[Link] = 0;
[Link] = "Not Assigned";
[Link]("Default constructor called");
}
// Parameterized constructor
public Student(String name, int age, String course) {
[Link] = name;
[Link] = age;
[Link] = course;
[Link]("Parameterized constructor called");
}
// Constructor with partial parameters
public Student(String name, int age) {
this(name, age, "General"); // Constructor chaining
}
// Constructor overloading
public Student(String name) {
this(name, 18, "General"); // Constructor chaining
}
}
// Usage
Student s1 = new Student(); // Default constructor
Student s2 = new Student("Alice", 20, "Computer Science");
Student s3 = new Student("Bob", 19); // Partial parameters
Student s4 = new Student("Carol"); // Single parameter
3. Inheritance in Detail
Types of Inheritance in Java:
// Single Inheritance
class Vehicle {
protected String brand;
protected int year;
public Vehicle(String brand, int year) {
[Link] = brand;
[Link] = year;
}
public void start() {
[Link]("Vehicle starting...");
}
public void stop() {
[Link]("Vehicle stopping...");
}
// Final method - cannot be overridden
public final void displayBrand() {
[Link]("Brand: " + brand);
}
}
// Single Inheritance
class Car extends Vehicle {
private int doors;
public Car(String brand, int year, int doors) {
super(brand, year); // Call parent constructor
[Link] = doors;
}
// Method overriding
@Override
public void start() {
[Link]("Car engine starting...");
}
// Additional method
public void honk() {
[Link]("Car honking!");
}
}
// Multilevel Inheritance
class SportsCar extends Car {
private int maxSpeed;
public SportsCar(String brand, int year, int doors, int maxSpeed) {
super(brand, year, doors);
[Link] = maxSpeed;
}
@Override
public void start() {
[Link]("Sports car roaring to life!");
}
public void turboBoost() {
[Link]("Turbo boost activated!");
}
}
// Hierarchical Inheritance
class Motorcycle extends Vehicle {
private boolean hasSidecar;
public Motorcycle(String brand, int year, boolean hasSidecar) {
super(brand, year);
[Link] = hasSidecar;
}
@Override
public void start() {
[Link]("Motorcycle engine starting...");
}
public void wheelie() {
[Link]("Doing a wheelie!");
}
}
Method Overriding Rules:
1. Method signature must be identical
2. Return type must be same or covariant
3. Access modifier cannot be more restrictive
4. Cannot override static, final, or private methods
5. Use @Override annotation for compile-time checking
4. Exception Handling
Exception Hierarchy:
Throwable
├── Error (Unchecked)
└── Exception
├── RuntimeException (Unchecked)
│ ├── NullPointerException
│ ├── ArrayIndexOutOfBoundsException
│ ├── IllegalArgumentException
│ └── NumberFormatException
└── Checked Exceptions
├── IOException
├── ClassNotFoundException
└── SQLException
Exception Handling Syntax:
public class ExceptionHandlingExample {
public void demonstrateExceptions() {
// Try-catch block
try {
int result = divide(10, 0);
[Link]("Result: " + result);
} catch (ArithmeticException e) {
[Link]("Cannot divide by zero: " + [Link]());
} catch (Exception e) {
[Link]("General exception: " + [Link]());
} finally {
[Link]("Finally block always executes");
}
}
// Multiple catch blocks
public void readFile(String filename) {
try {
FileReader file = new FileReader(filename);
BufferedReader buffer = new BufferedReader(file);
String line = [Link]();
[Link](line);
[Link]();
} catch (FileNotFoundException e) {
[Link]("File not found: " + [Link]());
} catch (IOException e) {
[Link]("IO error: " + [Link]());
}
}
// Try-with-resources (Java 7+)
public void readFileWithResources(String filename) {
try (FileReader file = new FileReader(filename);
BufferedReader buffer = new BufferedReader(file)) {
String line = [Link]();
[Link](line);
} catch (IOException e) {
[Link]("IO error: " + [Link]());
}
}
// Method that throws exception
public int divide(int a, int b) throws ArithmeticException {
if (b == 0) {
throw new ArithmeticException("Division by zero is not allowed");
}
return a / b;
}
// Custom exception
public void validateAge(int age) throws InvalidAgeException {
if (age < 0 || age > 150) {
throw new InvalidAgeException("Invalid age: " + age);
}
}
}
// Custom exception class
class InvalidAgeException extends Exception {
public InvalidAgeException(String message) {
super(message);
}
}
5. Collections Framework
Collection Hierarchy:
Collection Interface
├── List (Ordered, Allows Duplicates)
│ ├── ArrayList
│ ├── LinkedList
│ └── Vector
├── Set (No Duplicates)
│ ├── HashSet
│ ├── LinkedHashSet
│ └── TreeSet
└── Queue
├── PriorityQueue
└── Deque
└── ArrayDeque
Map Interface (Key-Value Pairs)
├── HashMap
├── LinkedHashMap
├── TreeMap
└── Hashtable
ArrayList Example:
import [Link].*;
public class CollectionExamples {
public void arrayListDemo() {
// Create ArrayList
List<String> fruits = new ArrayList<>();
// Add elements
[Link]("Apple");
[Link]("Banana");
[Link]("Orange");
[Link]("Apple"); // Duplicates allowed
// Access elements
[Link]("First fruit: " + [Link](0));
// Iterate using enhanced for loop
for (String fruit : fruits) {
[Link](fruit);
}
// Iterate using iterator
Iterator<String> iter = [Link]();
while ([Link]()) {
[Link]([Link]());
}
// Size and contains
[Link]("Size: " + [Link]());
[Link]("Contains Apple: " + [Link]("Apple"));
// Remove element
[Link]("Banana");
[Link](0); // Remove by index
}
public void hashSetDemo() {
Set<Integer> numbers = new HashSet<>();
[Link](1);
[Link](2);
[Link](3);
[Link](2); // Duplicate - won't be added
[Link]("Set size: " + [Link]()); // Output: 3
// Iterate
for (Integer num : numbers) {
[Link](num);
}
}
public void hashMapDemo() {
Map<String, Integer> studentGrades = new HashMap<>();
// Put key-value pairs
[Link]("Alice", 95);
[Link]("Bob", 87);
[Link]("Charlie", 92);
// Get value by key
Integer aliceGrade = [Link]("Alice");
[Link]("Alice's grade: " + aliceGrade);
// Check if key exists
if ([Link]("Bob")) {
[Link]("Bob's grade: " + [Link]("Bob"));
}
// Iterate over entries
for ([Link]<String, Integer> entry : [Link]()) {
[Link]([Link]() + ": " + [Link]());
}
// Iterate over keys
for (String student : [Link]()) {
[Link](student + ": " + [Link](student));
}
// Iterate over values
for (Integer grade : [Link]()) {
[Link]("Grade: " + grade);
}
}
}
6. Interfaces and Abstract Classes
Interface Example:
// Interface definition
interface Drawable {
// Public static final by default
int MAX_SIZE = 100;
// Public abstract by default
void draw();
void resize(int factor);
// Default method (Java 8+)
default void print() {
[Link]("Printing drawable object");
}
// Static method (Java 8+)
static void info() {
[Link]("This is Drawable interface");
}
}
// Multiple inheritance through interfaces
interface Colorable {
void setColor(String color);
String getColor();
}
// Implementation class
class Circle implements Drawable, Colorable {
private int radius;
private String color;
public Circle(int radius) {
[Link] = radius;
[Link] = "Black"; // Default color
}
@Override
public void draw() {
[Link]("Drawing a circle with radius " + radius);
}
@Override
public void resize(int factor) {
[Link] *= factor;
[Link]("Circle resized. New radius: " + radius);
}
@Override
public void setColor(String color) {
[Link] = color;
}
@Override
public String getColor() {
return color;
}
}
Abstract Class Example:
abstract class Animal {
protected String name;
protected int age;
// Constructor in abstract class
public Animal(String name, int age) {
[Link] = name;
[Link] = age;
}
// Concrete method
public void sleep() {
[Link](name + " is sleeping");
}
// Abstract method - must be implemented by subclasses
public abstract void makeSound();
public abstract void move();
// Getter methods
public String getName() { return name; }
public int getAge() { return age; }
}
// Concrete implementation
class Dog extends Animal {
private String breed;
public Dog(String name, int age, String breed) {
super(name, age);
[Link] = breed;
}
@Override
public void makeSound() {
[Link](name + " barks: Woof! Woof!");
}
@Override
public void move() {
[Link](name + " runs on four legs");
}
// Additional method
public void fetch() {
[Link](name + " fetches the ball");
}
}
class Bird extends Animal {
private boolean canFly;
public Bird(String name, int age, boolean canFly) {
super(name, age);
[Link] = canFly;
}
@Override
public void makeSound() {
[Link](name + " chirps");
}
@Override
public void move() {
if (canFly) {
[Link](name + " flies in the sky");
} else {
[Link](name + " walks on the ground");
}
}
}
Interview Questions by Category
Object-Oriented Programming Interview Questions
Basic OOP Questions
Q1: What is Object-Oriented Programming?
Answer: Object-Oriented Programming (OOP) is a programming paradigm based on the concept of "objects" that contain data
(attributes) and code (methods). It focuses on modeling real-world entities as objects that interact with each other.
Key Principles:
Encapsulation: Bundling data and methods together
Inheritance: Creating new classes based on existing ones
Polymorphism: Same interface, different implementations
Abstraction: Hiding complex implementation details
Q2: What is the difference between a class and an object?
Answer:
Class: A blueprint or template that defines the structure and behavior of objects
Object: An actual instance of a class with specific values
Example:
// Class definition
class Car {
String brand;
String model;
void start() { /* implementation */ }
}
// Object creation
Car myCar = new Car(); // myCar is an object of Car class
Q3: Explain the four pillars of OOP.
Answer:
1. Encapsulation:
Bundling data and methods together
Data hiding using access modifiers
Controlled access through getter/setter methods
2. Inheritance:
Creating new classes based on existing classes
Promotes code reusability
IS-A relationship
3. Polymorphism:
One interface, multiple implementations
Method overloading (compile-time)
Method overriding (runtime)
4. Abstraction:
Hiding implementation complexity
Showing only essential features
Achieved through abstract classes and interfaces
Advanced OOP Questions
Q4: What is the difference between method overloading and method overriding?
Answer:
Method Overloading Method Overriding
Same method name, different parameters Same method signature in parent and child
Compile-time polymorphism Runtime polymorphism
Within same class Between parent and child classes
Method Overloading Method Overriding
Return type can be different Return type must be same or covariant
Q5: What is the difference between abstract class and interface?
Answer:
Abstract Class Interface
Can have concrete methods All methods are abstract (before Java 8)
Can have instance variables Only constants (public static final)
Single inheritance Multiple inheritance supported
Can have constructors Cannot have constructors
Use extends keyword Use implements keyword
Q6: When would you use composition over inheritance?
Answer:
Composition should be preferred when:
You need flexibility in changing behavior at runtime
You want to avoid tight coupling
The relationship is "HAS-A" rather than "IS-A"
You need to inherit from multiple sources
Example:
// Composition approach
class Car {
private Engine engine; // HAS-A relationship
private Transmission transmission;
public Car(Engine engine, Transmission transmission) {
[Link] = engine;
[Link] = transmission;
}
}
Data Structures & Algorithms Interview Questions
Array Questions
Q1: Find the second largest element in an array.
Answer:
public int findSecondLargest(int[] arr) {
if ([Link] < 2) {
throw new IllegalArgumentException("Array must have at least 2 elements");
}
int largest = Integer.MIN_VALUE;
int secondLargest = Integer.MIN_VALUE;
for (int num : arr) {
if (num > largest) {
secondLargest = largest;
largest = num;
} else if (num > secondLargest && num != largest) {
secondLargest = num;
}
}
if (secondLargest == Integer.MIN_VALUE) {
throw new IllegalArgumentException("No second largest element found");
}
return secondLargest;
}
Q2: Rotate an array by k positions.
Answer:
public void rotateArray(int[] arr, int k) {
int n = [Link];
k = k % n; // Handle cases where k > n
// Reverse entire array
reverse(arr, 0, n - 1);
// Reverse first k elements
reverse(arr, 0, k - 1);
// Reverse remaining elements
reverse(arr, k, n - 1);
}
private void reverse(int[] arr, int start, int end) {
while (start < end) {
int temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
}
Linked List Questions
Q3: Detect if a linked list has a cycle.
Answer:
public boolean hasCycle(ListNode head) {
if (head == null || [Link] == null) {
return false;
}
ListNode slow = head;
ListNode fast = head;
while (fast != null && [Link] != null) {
slow = [Link];
fast = [Link];
if (slow == fast) {
return true;
}
}
return false;
}
Q4: Reverse a linked list.
Answer:
public ListNode reverseList(ListNode head) {
ListNode prev = null;
ListNode current = head;
while (current != null) {
ListNode next = [Link];
[Link] = prev;
prev = current;
current = next;
}
return prev; // New head
}
Tree Questions
Q5: Find the maximum depth of a binary tree.
Answer:
public int maxDepth(TreeNode root) {
if (root == null) {
return 0;
}
int leftDepth = maxDepth([Link]);
int rightDepth = maxDepth([Link]);
return 1 + [Link](leftDepth, rightDepth);
}
Q6: Check if a binary tree is symmetric.
Answer:
public boolean isSymmetric(TreeNode root) {
if (root == null) {
return true;
}
return isSymmetricHelper([Link], [Link]);
}
private boolean isSymmetricHelper(TreeNode left, TreeNode right) {
if (left == null && right == null) {
return true;
}
if (left == null || right == null) {
return false;
}
return ([Link] == [Link]) &&
isSymmetricHelper([Link], [Link]) &&
isSymmetricHelper([Link], [Link]);
}
SQL Interview Questions
Basic SQL Questions
Q1: What is the difference between WHERE and HAVING clauses?
Answer:
WHERE: Filters individual rows before grouping
HAVING: Filters grouped results after GROUP BY
-- WHERE example
SELECT * FROM Employees WHERE Salary > 50000;
-- HAVING example
SELECT Department, AVG(Salary)
FROM Employees
GROUP BY Department
HAVING AVG(Salary) > 60000;
Q2: Explain different types of SQL joins.
Answer:
1. INNER JOIN: Returns matching records from both tables
2. LEFT JOIN: Returns all records from left table and matching from right
3. RIGHT JOIN: Returns all records from right table and matching from left
4. FULL OUTER JOIN: Returns all records from both tables
-- INNER JOIN
SELECT [Link], [Link]
FROM Employees e
INNER JOIN Departments d ON [Link] = [Link];
-- LEFT JOIN
SELECT [Link], [Link]
FROM Employees e
LEFT JOIN Departments d ON [Link] = [Link];
Advanced SQL Questions
Q3: Write a query to find the second highest salary.
Answer:
-- Method 1: Using LIMIT and OFFSET
SELECT DISTINCT Salary
FROM Employees
ORDER BY Salary DESC
LIMIT 1 OFFSET 1;
-- Method 2: Using subquery
SELECT MAX(Salary) as SecondHighest
FROM Employees
WHERE Salary < (SELECT MAX(Salary) FROM Employees);
-- Method 3: Using ROW_NUMBER()
SELECT Salary
FROM (
SELECT Salary, ROW_NUMBER() OVER (ORDER BY Salary DESC) as rn
FROM Employees
) ranked
WHERE rn = 2;
Q4: Explain database normalization.
Answer:
Normalization is the process of organizing database tables to minimize redundancy and dependency.
Normal Forms:
1NF: Eliminate duplicate columns, atomic values
2NF: 1NF + eliminate partial dependencies
3NF: 2NF + eliminate transitive dependencies
BCNF: 3NF + every determinant is a candidate key
Q5: What is the difference between UNION and UNION ALL?
Answer:
UNION: Combines results and removes duplicates
UNION ALL: Combines results including duplicates (faster)
-- UNION (removes duplicates)
SELECT City FROM Customers
UNION
SELECT City FROM Suppliers;
-- UNION ALL (includes duplicates)
SELECT City FROM Customers
UNION ALL
SELECT City FROM Suppliers;
Java Programming Interview Questions
Core Java Questions
Q1: What is the difference between == and .equals() in Java?
Answer:
== compares references (memory addresses) for objects, values for primitives
.equals() compares actual content of objects
String s1 = new String("hello");
String s2 = new String("hello");
String s3 = "hello";
String s4 = "hello";
[Link](s1 == s2); // false (different objects)
[Link]([Link](s2)); // true (same content)
[Link](s3 == s4); // true (string pool)
Q2: Explain the concept of constructor chaining.
Answer:
Constructor chaining is calling one constructor from another constructor in the same class or parent class.
public class Employee {
private String name;
private int id;
private double salary;
// Constructor 1
public Employee() {
this("Unknown", 0, 0.0); // Call constructor 3
}
// Constructor 2
public Employee(String name, int id) {
this(name, id, 0.0); // Call constructor 3
}
// Constructor 3
public Employee(String name, int id, double salary) {
[Link] = name;
[Link] = id;
[Link] = salary;
}
}
Q3: What is the difference between String, StringBuffer, and StringBuilder?
Answer:
Feature String StringBuffer StringBuilder
Mutability Immutable Mutable Mutable
Thread Safety Thread-safe Thread-safe Not thread-safe
Performance Slow for modifications Moderate Fast
Memory Creates new objects Modifies existing Modifies existing
// String - Immutable
String str = "Hello";
str += " World"; // Creates new String object
// StringBuffer - Thread-safe, mutable
StringBuffer sb = new StringBuffer("Hello");
[Link](" World"); // Modifies existing object
// StringBuilder - Not thread-safe, mutable, fastest
StringBuilder builder = new StringBuilder("Hello");
[Link](" World"); // Modifies existing object
Advanced Java Questions
Q4: Explain the collections hierarchy in Java.
Answer:
Collection (Interface)
├── List (Interface) - Ordered, allows duplicates
│ ├── ArrayList - Resizable array, fast random access
│ ├── LinkedList - Doubly-linked list, fast insertion/deletion
│ └── Vector - Synchronized ArrayList
├── Set (Interface) - No duplicates
│ ├── HashSet - Hash table based, no order
│ ├── LinkedHashSet - Hash table + linked list, insertion order
│ └── TreeSet - Red-black tree, sorted order
└── Queue (Interface) - FIFO
├── PriorityQueue - Heap-based priority queue
└── Deque (Interface)
└── ArrayDeque - Resizable array deque
Map (Interface) - Key-value pairs
├── HashMap - Hash table based, no order
├── LinkedHashMap - Hash table + linked list, insertion order
└── TreeMap - Red-black tree, sorted by keys
Q5: What is the difference between ArrayList and LinkedList?
Answer:
Feature ArrayList LinkedList
Internal Structure Dynamic array Doubly linked list
Random Access O(1) O(n)
Insertion at beginning O(n) O(1)
Insertion at end O(1) amortized O(1)
Memory Overhead Less More (node pointers)
Cache Performance Better Worse
When to use:
ArrayList: When you need frequent random access to elements
LinkedList: When you need frequent insertions/deletions at beginning/middle
Tips for Technical Interview Success
Preparation Strategy
1. Understand Fundamentals: Master core concepts before moving to advanced topics
2. Practice Coding: Write code by hand and on computer regularly
3. Think Aloud: Explain your thought process during problem solving
4. Ask Questions: Clarify requirements and edge cases
5. Test Your Code: Always trace through your solution with examples
Problem-Solving Approach
1. Understand the Problem: Read carefully and ask clarifying questions
2. Plan Your Solution: Think before coding, consider different approaches
3. Start Simple: Begin with brute force, then optimize
4. Write Clean Code: Use meaningful variable names and proper structure
5. Test and Debug: Check for edge cases and potential errors
Common Mistakes to Avoid
1. Jumping into coding without understanding the problem
2. Not considering edge cases or error conditions
3. Writing overly complex solutions when simple ones exist
4. Not explaining your approach or reasoning
5. Giving up too quickly when stuck
Final Preparation Checklist
[ ] Review all four major topics (OOP, DSA, SQL, Java)
[ ] Practice coding problems on paper and computer
[ ] Prepare questions to ask the interviewer
[ ] Review your projects and be ready to discuss them
[ ] Get good rest before the interview
[ ] Arrive early and stay calm during the interview
Good luck with your Experion Technologies technical interview!