SQL / Database
Q: Write a SQL query to get departments with a total salary greater than 3 lakhs.
A: SELECT d.department_name, SUM(e.salary) AS total_salary
FROM Employee e
JOIN Department d ON e.department_id = d.id
GROUP BY d.department_name
HAVING total_salary > 300000;
Q: Types of indexes in MySQL
A: 1. Primary Index
2. Unique Index
3. Composite Index
4. Full-text Index
5. Spatial Index
Q: Types of functions in MySQL
A: 1. Aggregate Functions (e.g., COUNT, SUM, AVG)
2. Scalar Functions (e.g., UPPER, NOW, LENGTH)
3. String Functions
4. Date Functions
5. Numeric Functions
Hibernate / JPA
Q: Write entity classes for Employee and Department with proper mappings.
A: @Entity
class Department {
@Id
private Long id;
private String name;
@OneToMany(mappedBy = "department")
private List<Employee> employees;
@Entity
class Employee {
@Id
private Long id;
private String name;
private double salary;
@ManyToOne
@JoinColumn(name = "department_id")
private Department department;
Java / Collections
Q: Internal working of HashMap
A: Uses array of buckets. Each bucket is a LinkedList or TreeNode (for collisions). Uses hashCode() and
equals().
Q: HashMap vs TreeMap
A: HashMap: Unordered, fast lookup.
TreeMap: Sorted by keys, slower operations.
Q: Issues with HashMap
A: 1. Collision handling
2. Hash collisions degrade performance
3. Fails in multi-threading without synchronization
Q: Load factor in HashMap
A: Determines when to resize. Default is 0.75.
Q: In case of collision, which type of LinkedList is used internally?
A: Initially LinkedList. If entries exceed threshold, it converts to Tree (TreeNode).
Java Concepts
Q: Difference between Comparator and Comparable
A: Comparable: compareTo(), used for natural ordering.
Comparator: compare(), used for custom sorting.
Q: String str = new String("amit"); vs String str1 = "amit"
A: str creates new object in heap; str1 uses String pool. Hence, str == str1 is false.
Q: Which Collection to use to maintain natural sorting and prevent duplicates?
A: TreeSet
Q: Collection Framework fundamentals
A: Provides interfaces and classes for storing and manipulating groups of data as a single unit.
Q: Generics overview
A: Provides compile-time type safety. Example: List<String>.
Spring Boot
Q: Ways of transaction management
A: 1. Programmatic
2. Declarative using @Transactional
Q: Parameters in @Transactional
A: propagation, isolation, readOnly, rollbackFor
Q: Bean lifecycle and scopes
A: Scopes: singleton, prototype, request, session.
Lifecycle: constructor setters init destroy.
Q: BeanFactory explanation
A: An interface for accessing Spring beans lazily.
Q: What is ViewResolver?
A: Resolves logical view names to actual views, e.g., JSP or Thymeleaf.
Java 8 Features
Q: Functional Interfaces usage of Supplier, BiPredicate
A: Supplier: () -> value
BiPredicate: (a, b) -> condition
Q: Practical examples where they are needed
A: Supplier for lazy loading.
BiPredicate for filtering with two conditions.
Q: Streams question
A: Used to process collections: filter, map, reduce.
Example: list.stream().filter(x -> x > 10).collect(Collectors.toList());