These are the notes for Low-Level Design (LLD) episode 1. You will see why code that works today can break tomorrow, what software design means, the difference between high-level design (HLD) and low-level design (LLD), how to go from requirements to entities, classes and interfaces, the five things every interviewer checks, how a machine-coding round and a design discussion round work, and the Java tools we use all through the course (JDK, javac, java, the main method). Every program below was run with javac Main.java && java -cp . Main (Java 21), exactly as the SyntaxPilot compiler runs it, and every output and error message is real.
The problem: a parking lot at a mall
A mall has a small parking lot: 1 bike spot and 2 car spots. Vehicles arrive one by one (a car, a bike, a car, a truck). Each vehicle needs a free spot of its own type and pays a fee: Rs 40 for a car, Rs 20 for a bike. Your manager asks you to write the program.
The obvious first attempt
Most people write it like this: an array (a numbered row of boxes) for the spot types, a second array for which spots are taken, and an if for the fee.
public class Main {
public static void main(String[] args) {
String[] spots = {"BIKE", "CAR", "CAR"};
boolean[] taken = new boolean[3];
String[] arrivals = {"CAR", "BIKE", "CAR", "TRUCK"};
for (String v : arrivals) {
int found = -1;
for (int i = 0; i < spots.length; i++)
if (!taken[i] && spots[i].equals(v)) { found = i; break; }
if (found == -1) { System.out.println(v + ": no spot"); continue; }
taken[found] = true;
int fee = v.equals("CAR") ? 40 : 20;
System.out.println(v + " -> spot " + found + ", fee Rs " + fee);
}
}
}
Output:
CAR -> spot 1, fee Rs 40
BIKE -> spot 0, fee Rs 20
CAR -> spot 2, fee Rs 40
TRUCK: no spot
Correct. The truck gets no spot because there is no truck spot.
The requirement changes: trucks
Next week the manager builds a truck spot; trucks pay Rs 100. The "obvious" edit is to add "TRUCK" to spots:
String[] spots = {"BIKE", "CAR", "CAR", "TRUCK"};
boolean[] taken = new boolean[3]; // forgot to change this
CAR -> spot 1, fee Rs 40
BIKE -> spot 0, fee Rs 20
CAR -> spot 2, fee Rs 40
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3
at Main.main(Main.java:9)
An exception is Java's way of saying "something went wrong while running; I have to stop". Two arrays describe the same spots, and only one of them grew.
Fix the size (new boolean[4]) and run again:
CAR -> spot 1, fee Rs 40
BIKE -> spot 0, fee Rs 20
CAR -> spot 2, fee Rs 40
TRUCK -> spot 3, fee Rs 20
No crash, but the truck is charged Rs 20 instead of Rs 100. The fee rule v.equals("CAR") ? 40 : 20 says "40 for a car, otherwise 20", and nobody remembered it. There was no error at all, just a wrong bill: the most dangerous kind of bug.
Why it broke
- Everything about one spot is split across two arrays that must always match.
- The fee rule hides inside an
ifin the middle of a loop; nothing ties it to the word "truck". - Adding one new vehicle type meant editing several lines, and missing one gave a wrong answer.
The code worked. What was wrong was its shape: how the program was split into pieces. Choosing that shape on purpose, before and while you code, is software design.
High-level design vs low-level design
| High-level design (HLD) | Low-level design (LLD) | |
|---|---|---|
| Real-life picture | The map of a whole township: towers, roads, water tank, power | The floor plan of one flat: rooms, doors, which switch controls which light |
| The boxes are | Machines and services: mobile app, API server, database, payment service | Classes, interfaces, methods |
| Main question | What runs where, and how do the pieces talk over the network? | Which class does what, and how do the classes connect? |
| Interview round | System design round | Machine-coding round, design discussion round |
| SyntaxPilot course | System Design | This course |
Both are needed. HLD decides that there is a "parking service"; LLD decides what classes live inside that service.
Step 1: requirements
A requirement is one thing the system must do, written in plain words. For the parking lot:
- A vehicle parks in a free spot of its own type.
- Each vehicle type has its own fee.
- If there is no free spot, say "no spot".
- New vehicle types will come later. (The one we ignored.)
Requirements that describe what the system does are called functional requirements. In an interview you get them by asking clarifying questions before you write any code: What must it do? What will change? What is out of scope?
Step 2: entities (the noun hunt)
An entity is one real thing in the problem that the program must remember or act on. A quick way to find them: underline the nouns in the requirements.
| Words in the requirements | Becomes |
|---|---|
| "a vehicle..." | entity Vehicle |
| "...parks in a spot of a parking lot" | entity ParkingLot (which keeps the spots) |
| "...pays a fee" | a method fee() that belongs to Vehicle |
Verbs and facts ("pays a fee", "parks") become behaviour (methods) of the entity they belong to. The fee belongs to the vehicle, not to a random if.
Step 3: classes and interfaces
| Real life | Java | Meaning |
|---|---|---|
| An admission-form template | class | A blueprint that keeps some data and the actions on that data together |
| One filled-in form (Aarav, roll 12) | object | One real thing made from a class |
| "Deposit", "print fee" | method | A named block of code you can call, like fee() |
| A wall-socket standard: any plug of the right shape works | interface | A promise: any class that implements it must provide these methods. It says what, not how |
Episodes 2 and 3 go deep into classes, objects and interfaces. Here they fix our bug.
The designed version
import java.util.*;
interface Vehicle { String type(); int fee(); }
class Car implements Vehicle {
public String type() { return "CAR"; }
public int fee() { return 40; }
}
class Bike implements Vehicle {
public String type() { return "BIKE"; }
public int fee() { return 20; }
}
class ParkingLot {
private final List<String> freeSpots = new ArrayList<>();
void addSpot(String type) { freeSpots.add(type); }
String park(Vehicle v) {
if (!freeSpots.remove(v.type())) return v.type() + ": no spot";
return v.type() + " parked, fee Rs " + v.fee();
}
}
public class Main {
public static void main(String[] args) {
ParkingLot lot = new ParkingLot();
for (String spot : List.of("BIKE", "CAR", "CAR"))
lot.addSpot(spot);
for (Vehicle v : List.of(new Car(), new Bike(), new Car()))
System.out.println(lot.park(v));
}
}
CAR parked, fee Rs 40
BIKE parked, fee Rs 20
CAR parked, fee Rs 40
How it works:
interface Vehicleis the promise: every vehicle can tell itstype()and itsfee(). The methods have no body, only a semicolon.CarandBikeimplement the interface: each one keeps the promise and holds its own fee.ParkingLotkeeps a list of free spot types (a list is like an array that can grow and shrink).freeSpots.remove(v.type())removes one free spot of that type and returnstrue, or returnsfalseif there is none.- The parking lot never asks "are you a car?". It only knows the word
Vehicle.
Adding trucks now
Add one new class, plus a truck spot and a truck in main. The parking lot is not touched:
class Truck implements Vehicle {
public String type() { return "TRUCK"; }
public int fee() { return 100; }
}
// in main:
for (String spot : List.of("BIKE", "CAR", "CAR", "TRUCK"))
lot.addSpot(spot);
for (Vehicle v : List.of(new Car(), new Bike(), new Car(), new Truck()))
System.out.println(lot.park(v));
CAR parked, fee Rs 40
BIKE parked, fee Rs 20
CAR parked, fee Rs 40
TRUCK parked, fee Rs 100
And if you forget the truck's fee, the compiler stops you before the program runs:
Main.java:12: error: Truck is not abstract and does not override abstract method fee() in Vehicle
class Truck implements Vehicle {
^
1 error
The wrong bill from the array version is now impossible. New feature = new class, not edits everywhere. That is low-level design.
The class diagram
A class diagram draws each class as a box. A dashed line with a hollow triangle means "implements this interface"; a dashed arrow means "uses".
«interface» Vehicle
+ type(): String
+ fee(): int
^ ^ ^ (dashed, hollow triangle = implements)
Car ------+ | +------ Truck
Bike
ParkingLot - - - uses - - -> Vehicle
- freeSpots: List
+ park(v): String
The five things interviewers check
These are the evaluation criteria: the rules your design is graded on.
| Criterion | Plain meaning | Real-life picture | In our parking lot |
|---|---|---|---|
| Correctness | Right output for every case, including edge cases (unusual inputs, like a lot with zero spots) | A bill that always adds up | The array version charged a truck Rs 20 |
| Readability | A stranger understands it quickly: good names, small methods | A well-labelled kitchen where a guest finds the sugar | lot.park(v) reads like English |
| Extensibility | A new feature means adding code, not rewriting old code | A plug that fits any standard socket | Truck = one new class |
| Modularity | Split into small parts (modules), each with one job | Train coaches: add or swap one without rebuilding the train | Vehicle, ParkingLot each have one job |
| Testability | Each part can be checked on its own | Testing one bulb without rewiring the house | new Truck().fee() can be checked alone |
Interview reports for Indian product companies describe it the same way: readable classes and clear separation of duties matter more than clever algorithms.
Machine-coding round vs design discussion round
Machine-coding round: a timed session in which you build a small working program on a laptop. Reported problems include a parking lot, a snake and ladder game, and a cache (a small, fast memory for recent results) with an eviction rule. Candidates report it at about 90 minutes, sometimes up to two hours, followed by a review discussion of about 15 to 30 minutes where you walk through your classes and are often asked to add a new feature without rewriting your existing classes. (Source: Design Gurus, "What Is the PhonePe Interview Process Like?")
A good machine-coding flow:
- Read the problem.
- Clarify requirements and what might change. Write them down.
- List entities (noun hunt) and sketch the classes and interfaces.
- Code the core, plus a small demo
mainthat shows it working. - Handle edge cases (no free spot, invalid input).
- Review: explain your choices; extend it live.
Design discussion round: you mostly talk and draw: a class diagram on a whiteboard or document, the key methods, and trade-offs (choosing one benefit at the cost of another, and explaining why). Little or no full code.
| Machine-coding round | Design discussion round | |
|---|---|---|
| Output | Working, runnable code | Diagram + reasoning |
| Where | Your laptop, timed | Whiteboard or document |
| Judged on | Code that runs and is easy to extend | Clear entities, responsibilities, trade-offs |
The Java tools: JDK, javac, java, main
| Term | Meaning |
|---|---|
| JDK (Java Development Kit) | The whole toolbox you install: the compiler, the JVM, and a large library of ready-made classes |
| javac | The Java compiler: it checks every line of Main.java and, if all is well, translates it into bytecode in Main.class |
| bytecode | A compact set of instructions not tied to one computer |
| java | The launcher: java Main starts the JVM (Java Virtual Machine), which runs the bytecode on Windows, macOS or Linux alike |
| main method | The front door where every Java program starts: public static void main(String[] args) |
The SyntaxPilot online compiler runs javac Main.java && java Main for you; you can see the command at the top of its terminal.
Misspell main:
public class Main {
public static void hello(String[] args) {
System.out.println("Parking lot ready");
}
}
Error: Main method not found in class Main, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
javac accepted it (it is valid code), but java found no front door.
Forget a semicolon:
Main.java:3: error: ';' expected
System.out.println("Parking lot ready")
^
1 error
That is a compile error: caught by javac before the program runs. Add the semicolon and it prints Parking lot ready.
Common mistakes
| Mistake | Exact message / symptom | Why | Fix |
|---|---|---|---|
| Two arrays describe one thing | ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3 |
One array grew, the other didn't | Keep one thing's data in one class |
A business rule hidden in an if |
No error: TRUCK -> spot 3, fee Rs 20 |
Nobody remembered the hidden rule | Put the fee inside each Vehicle class |
| A class skips an interface method | Truck is not abstract and does not override abstract method fee() in Vehicle |
The class broke its promise | Write every method the interface asks for |
No main method |
Error: Main method not found in class Main |
No starting point | public static void main(String[] args) |
| Missing semicolon | error: ';' expected |
Java statements end with ; |
Add the ; |
| Coding in the first minute of an interview | Wrong assumptions, rewrite at minute 60 | Requirements were never clarified | Ask questions, write requirements first |
Mini project: add a scooter
Add a Scooter with fee Rs 15 to the designed version, one scooter spot, and two scooters arriving.
Solution
class Scooter implements Vehicle {
public String type() { return "SCOOTER"; }
public int fee() { return 15; }
}
// in main:
for (String spot : List.of("BIKE", "CAR", "CAR", "TRUCK", "SCOOTER"))
lot.addSpot(spot);
for (Vehicle v : List.of(new Car(), new Bike(), new Car(), new Truck(), new Scooter(), new Scooter()))
System.out.println(lot.park(v));
CAR parked, fee Rs 40
BIKE parked, fee Rs 20
CAR parked, fee Rs 40
TRUCK parked, fee Rs 100
SCOOTER parked, fee Rs 15
SCOOTER: no spot
ParkingLot did not change at all: that is extensibility.
Practice
- Write four functional requirements for a small library that lends books and magazines.
Solution
- A member can borrow an item that is on the shelf.
- Books are lent for 14 days, magazines for 3 days.
- An item that is already lent out is "not available".
- New item types (for example DVDs) will be added later.
- Do the noun hunt on your requirements. Which entities and which methods do you get?
Solution
Nouns: member, item, book, magazine, shelf / library. Entities: Item (an interface), Book, Magazine, Library. Facts and verbs: "lent for 14 days" → loanDays() on each item; "borrow" → lend(title) on Library.
- Code it with an
Iteminterface, so that a DVD could be added later as one new class.
Solution
import java.util.*;
interface Item { String title(); int loanDays(); }
class Book implements Item {
private final String title;
Book(String title) { this.title = title; }
public String title() { return title; }
public int loanDays() { return 14; }
}
class Magazine implements Item {
private final String title;
Magazine(String title) { this.title = title; }
public String title() { return title; }
public int loanDays() { return 3; }
}
class Library {
private final List<Item> shelf = new ArrayList<>();
void add(Item i) { shelf.add(i); }
String lend(String title) {
for (Item i : shelf)
if (i.title().equals(title)) { shelf.remove(i); return title + ": due in " + i.loanDays() + " days"; }
return title + ": not available";
}
}
public class Main {
public static void main(String[] args) {
Library lib = new Library();
lib.add(new Book("Java Basics")); lib.add(new Magazine("Tech Today"));
System.out.println(lib.lend("Java Basics"));
System.out.println(lib.lend("Tech Today"));
System.out.println(lib.lend("Java Basics"));
}
}
Java Basics: due in 14 days
Tech Today: due in 3 days
Java Basics: not available
(Removing from the list inside the for-each loop is safe here only because we return immediately afterwards; episode 40 explains why.)
- Is "the app must respond within 200 ms" a functional requirement?
Solution
No. It says how well the system must work, not what it does. That is a non-functional requirement (speed, reliability, security). Episode 20 covers both kinds.
Quick quiz
Adding a TRUCK spot crashed the array version and then charged the truck Rs 20. Which quality was the old design missing most?
- Speed
- Extensibility
- Testability of the JVM
- Fewer classes
Answer
Extensibility. A new vehicle type should mean adding code, not editing many lines and hoping you caught them all. Correctness broke because the design was not extensible.
Interview questions
- What is the difference between HLD and LLD? HLD decides the machines and services and how they talk (servers, databases, queues). LLD decides the classes, interfaces and methods inside one service and how they connect.
- What do you do in the first 10 minutes of a machine-coding round? Clarify requirements and what may change, write them down, list entities, sketch the classes. Then code.
- What is an interface, in one sentence? A promise of methods a class must provide, describing what it can do but not how.
- How do you show extensibility in a demo? Add a new type (like
Truck) as a new class without editing existing classes. - Why is a silent wrong answer worse than a crash? A crash is noticed immediately; a wrong bill can go unnoticed for weeks.
- What is the role of
mainin a machine-coding solution? It is the demo driver: it builds the objects and shows each requirement working, including edge cases.
Glossary
| Term | Meaning, with an example |
|---|---|
| Software design | Deciding the parts of a program and how they talk, on purpose. Example: splitting parking into Vehicle and ParkingLot |
| High-level design (HLD) | Design at the level of machines and services. Example: app → API server → database |
| Low-level design (LLD) | Design inside one program: classes, interfaces, methods. Example: ParkingLot.park(Vehicle) |
| Machine-coding round | A timed interview where you build a small working program, then review and extend it |
| Design discussion round | An interview where you explain a design with a diagram and trade-offs, with little code |
| Requirement | One thing the system must do. Example: "each vehicle type has its own fee" |
| Functional requirement | A requirement about what the system does |
| Non-functional requirement | A requirement about how well it works (speed, security) |
| Clarifying question | A question you ask before coding to pin down requirements |
| Entity | A real thing in the problem the program must remember or act on. Example: Vehicle |
| Noun hunt | Finding entities by underlining the nouns in the requirements |
| Class | A blueprint that keeps data and the actions on it together. Example: class Car |
| Object | One real thing made from a class. Example: new Car() |
| Method | A named block of code you can call. Example: fee() |
| Interface | A promise of methods that implementing classes must provide. Example: interface Vehicle |
| implements | The keyword with which a class promises to keep an interface |
| Class diagram | A drawing of classes as boxes and their relationships as lines |
| Array | A fixed-size numbered row of boxes. Example: new boolean[3] |
| List | A row of items that can grow and shrink. Example: ArrayList |
| Exception | Java's report that something went wrong while running |
| Compile error | A mistake javac finds before the program runs. Example: ';' expected |
| Evaluation criteria | The rules a design is graded on |
| Correctness | Right output for every case |
| Edge case | An unusual input, like a lot with zero spots |
| Readability | How quickly a stranger understands the code |
| Extensibility | Adding a feature by adding code, not rewriting |
| Modularity | Being split into small parts with one job each |
| Module | One such part |
| Testability | Being able to check each part on its own |
| Cache | A small, fast memory that keeps recent results |
| Trade-off | Choosing one benefit at the cost of another |
| JDK | Java Development Kit: compiler, JVM and libraries |
| javac | The Java compiler: .java → .class bytecode |
| Compiler | A program that checks and translates code into a runnable form |
| Bytecode | Compact instructions in a .class file, not tied to one computer |
| java | The launcher that starts the JVM and runs a class |
| JVM | Java Virtual Machine: runs bytecode on any operating system |
| main method | public static void main(String[] args): where a Java program starts |
| Terminal | The panel (or window) where a program's output appears |
Summary
- Working code can still have the wrong shape; design is choosing that shape on purpose.
- HLD = machines and services; LLD = classes, interfaces and methods inside one program.
- Go requirements → entities (noun hunt) → classes and interfaces.
- Put each rule inside the class it belongs to, and depend on interfaces: then a new feature is a new class.
- Interviewers grade correctness, readability, extensibility, modularity, testability.
- A machine-coding round = build and demo working code in about 90 minutes, then review and extend; a design discussion round = diagram and trade-offs.
javaccompiles,javaruns, andmainis where it starts.
Next episode: Java for LLD 1: classes, objects and access control.