Posted on: February 8, 2025 Posted by: rahulgite Comments: 0

Internal Working of LinkedHashSet in Java

Introduction A LinkedHashSet in Java is a part of the java.util package and is used to store unique elements while maintaining insertion order. It extends HashSet and uses a linked list to maintain order. Unlike HashSet, which does not guarantee the order of elements, LinkedHashSet ensures elements are returned in the same order they were inserted. 1. Data Structure Used LinkedHashSet is implemented using a combination of HashMap and a…

Posted on: February 8, 2025 Posted by: rahulgite Comments: 0

Internal Working of Vector in Java

Introduction A Vector in Java is a part of the java.util package and is used to store a dynamic array similar to ArrayList. However, Vector is synchronized, making it thread-safe but slower in comparison to ArrayList. 1. Data Structure Used Vector is implemented using a dynamic array, meaning it grows automatically when more elements are added. Implementation in Java: 2. How Elements are Stored and Accessed Adding an Element When…

Posted on: February 8, 2025 Posted by: rahulgite Comments: 0

Internal Working of LinkedList in Java

Introduction A LinkedList in Java is a part of the java.util package and is used to store elements in a doubly linked list structure. Unlike ArrayList, which uses a dynamic array, LinkedList consists of nodes that store data and references to the next and previous nodes. 1. Data Structure Used LinkedList is implemented using a doubly linked list where each node contains: Implementation in Java: When a LinkedList is created,…

Posted on: February 8, 2025 Posted by: rahulgite Comments: 0

Internal Working of ArrayList in Java

Introduction An ArrayList in Java is a part of the java.util package and is used to store dynamic arrays. Unlike arrays, ArrayList can grow dynamically when elements are added, making it more flexible. 1. Data Structure Used ArrayList is implemented using an array internally. The key feature of ArrayList is its ability to resize dynamically when elements are added or removed. Implementation in Java: 2. How Elements are Stored and…

Posted on: February 8, 2025 Posted by: rahulgite Comments: 0

Internal Working of TreeMap in Java

Introduction A TreeMap in Java is a part of the java.util package and is used to store key-value pairs in sorted order based on the natural ordering of keys or a custom comparator. Unlike HashMap, which provides constant-time performance (O(1)) for basic operations, TreeMap provides logarithmic time complexity (O(log n)) as it is implemented using a Red-Black Tree. 1. Data Structure Used A TreeMap is implemented as a Red-Black Tree,…

Posted on: February 8, 2025 Posted by: rahulgite Comments: 0

Internal Working of HashMap in Java

Introduction A HashMap in Java is a part of the java.util package and is used to store key-value pairs. It provides fast lookups, insertions, and deletions with an average time complexity of O(1). It internally uses a hashing mechanism to map keys to values efficiently. 1. Data Structure Used HashMap is implemented using an array of linked lists (or Red-Black Trees for optimization in Java 8+). Each bucket in the…

Posted on: February 8, 2025 Posted by: rahulgite Comments: 0

Internal Working of HashSet in Java

Introduction A HashSet in Java is a part of the java.util package and is used to store unique elements. It is backed by a HashMap, which helps in achieving constant-time complexity (O(1)) for add, remove, and contains operations. Internal Working of HashSet 1. Data Structure Used HashSet internally uses a HashMap<K, V> with a dummy value. Each element in the HashSet acts as a key in the HashMap, and the…

Posted on: February 8, 2025 Posted by: rahulgite Comments: 0

Execution Plan Analysis and Optimization

Introduction When dealing with large stored procedures or complex queries, it is essential to identify which part of the query is taking more time and optimize it. The execution plan is a vital tool in understanding how the database processes a query and helps in pinpointing performance bottlenecks. 1. Execution Plan in MySQL Using EXPLAIN To analyze a query’s execution plan in MySQL, use: This will output details about how…

Posted on: February 8, 2025 Posted by: rahulgite Comments: 1

Spring Autowiring

1. What is Autowiring in Spring? Autowiring in Spring is the process of automatically injecting dependent beans into a Spring-managed component. It helps in reducing manual bean configuration in the Spring application. 2. Types of Dependency Injection (DI) in Spring Spring supports three primary types of dependency injection: 3. Autowiring in Spring Framework Spring provides the following ways to autowire dependencies: 3.1 Using @Autowired (Most Common Approach) The @Autowired annotation…

Posted on: February 1, 2025 Posted by: rahulgite Comments: 0

Stack & Queue

Problem 1: Implement Stack using Queues Explanation: Implement a stack using only queues. Approach: Time & Space Complexity: Java Implementation: Example: Input: Output: Edge Cases Considered: Problem 2: Design Hit Counter Explanation: Design a hit counter that counts the number of hits received in the past 300 seconds. Approach: Time & Space Complexity: Java Implementation: Example: Input: Output: Edge Cases Considered: