Posts

Design a HashMap Low Level Design

Image
🧠 Understanding HashMap in Java 1. What is a HashMap? Definition : A HashMap is a part of Java's Collections Framework that stores data in key-value pairs. Key Characteristics : Unique Keys : Each key in a HashMap is unique. Allows Nulls : Both keys and values can be null . Unordered : The order of entries is not guaranteed. 2. Internal Structure Bucket Array : Internally, a HashMap uses an array of buckets to store data. Node Class : Each bucket contains a linked list (or a balanced tree in Java 8 and above) of Node objects, where each node represents a key-value pair.   static class Node< K , V > implements Map.Entry< K , V > { final int hash ; final K key ; V value ; Node< K , V > next ; } 3. How HashMap Stores Data Hashing : When a key-value pair is added: Calculate Hash : The hashCode() of the key is computed. Determine Bucket Index : The hash is used to determine the index in the bucket array. Handl...

Parking Lot Project Low Level Design

  🚗 Parking Lot Project — Interview Summary 🎯 Purpose This project simulates a Parking Lot Management System using Spring Boot + Core Java OOP Design Patterns . It allows: Adding parking floors and parking spots Parking and unparking vehicles Generating parking tickets Calculating parking fees using pricing strategies Making payments using different payment strategies ⚙️ High-Level Architecture 📦 1. Entity Layer ( entity package) Represents the core data objects : Vehicle Contains vehicle number and type ( CAR , BIKE , TRUCK ) ParkingSpot Has id , allowedType , and occupied status (AtomicBoolean for thread-safety) ParkingFloor Has id and multiple ParkingSpot objects in a ConcurrentHashMap Ticket Contains ticketId , entryTime , exitTime , vehicle , floorId , spotId , and paymentStatus ⚙️ 2. Enum Layer ( enumpack package) Defines system constants: VehicleType → CAR , BIKE , TRUCK PaymentMode → CASH , UPI , ...