Skip to lesson

Mock Round: Core Java, OOP and DSA (Stage 1-2)

A first technical round checks whether your Java basics survive follow-up questions and whether you can think aloud. Interviewers score the reason behind each answer, not only the answer.

The 45-minute script and its scoring rubric

A rubric is a fixed list of the parts of a round, each with a weight and a band from 0 to 4, that turns "it went fine" into a score out of 100 and shows your weakest part.

Example 1 shows the round minute by minute and Example 2 scores it. Run it with a timer and a friend as the interviewer, and do not pause the clock to look things up.

Example 1 · The 45-minute script

Text
00-05  INTRO          "Tell me about yourself." 60 to 90 seconds: studies, one                      project, what you want to work on.05-20  THEORY         8 questions on core Java and OOP, each with a follow-up.                      JVM/JDK, String and ==, static/final, pass by value,                      exceptions, overriding vs overloading, interface vs                      abstract class, equals/hashCode.20-27  OUTPUT         3 or 4 snippets: "What does this print, and why?"27-42  CODING         One problem: clarify, brute force, improve, code,                      dry run, complexity. Talk throughout.42-45  YOUR QUESTIONS One or two real questions about the team or the work.Weights: intro 10, theory 30, output 20, coding 30, communication 10
Timing
5 + 15 + 7 + 15 + 3 = 45 minutes, scored out of 100

What this code does

  • Theory and coding carry the most weight, which matches where most fresher rounds spend their time.
  • Communication is scored across the whole round, not in one slot: it is how you explain, ask and react to hints.
  • Keep your own questions short; one good question about the team's work is enough.

Example 2 · Score the round with weights and bands

RoundScoreDemo.javaJava
import java.util.LinkedHashMap;import java.util.Map;
public class RoundScoreDemo {    public static void main(String[] args) {        Map<String, Integer> weights = new LinkedHashMap<>();        weights.put("Intro", 10);        weights.put("Theory", 30);        weights.put("Output", 20);        weights.put("Coding", 30);        weights.put("Communication", 10);
        Map<String, Integer> bands = Map.of(                "Intro", 3, "Theory", 3, "Output", 2, "Coding", 3, "Communication", 4);
        double total = 0;        String weakest = null;        int lowestBand = 5;        for (Map.Entry<String, Integer> e : weights.entrySet()) {            int band = bands.get(e.getKey());            double points = e.getValue() * band / 4.0;            total += points;            System.out.printf("%-14s band %d/4  %5.1f of %d%n", e.getKey(), band, points, e.getValue());            if (band < lowestBand) {                lowestBand = band;                weakest = e.getKey();            }        }        String verdict = total >= 70 ? "likely to clear" : total >= 55 ? "borderline" : "not yet";        System.out.printf("Total: %.1f / 100, %s%n", total, verdict);        System.out.println("Practise next: " + weakest);    }}
Output
Intro          band 3/4    7.5 of 10
Theory         band 3/4   22.5 of 30
Output         band 2/4   10.0 of 20
Coding         band 3/4   22.5 of 30
Communication  band 4/4   10.0 of 10
Total: 72.5 / 100, likely to clear
Practise next: Output

What this code does

  • Points are weight × band / 4, so a band 2 on the output round gives half of its 20 points.
  • LinkedHashMap keeps the parts in script order for printing; Map.of is fine for the lookup table because order does not matter there.
  • The cut-offs (70 and 55) are this mock's own; use them to compare your mocks with each other, not to predict a company's decision.

Each part gets a band:

  • Band 4: correct, complete, clearly explained without help.
  • Band 3: correct with small gaps or one hint.
  • Band 2: partly correct, or correct only after several hints.
  • Band 0 to 1: wrong, missing, or guessed.

Weights differ between companies; this is a common shape for first technical rounds. Revise: Technical rounds explained (opens in a new tab).

Order of execution

Order the 45-minute round

Tap the parts in the order a first technical round usually runs them.

Theory questions: answer first, then reveal

A follow-up is the interviewer's next question on the same topic, asked one level deeper when an answer is shallow or good enough to test further.

Theory is about 15 minutes of questions, one after another. The follow-up is where marks are won: Example 3 proves the follow-up to equals, what happens when hashCode is missing.

Example 3 · Follow-up proof: equals without hashCode

EqualsHashCodeDemo.javaJava
import java.util.HashSet;import java.util.Objects;import java.util.Set;
class RollNoOnlyEquals {    final int roll;
    RollNoOnlyEquals(int roll) {        this.roll = roll;    }
    @Override    public boolean equals(Object o) {        return o instanceof RollNoOnlyEquals other && other.roll == roll;    }}
class RollNo {    final int roll;
    RollNo(int roll) {        this.roll = roll;    }
    @Override    public boolean equals(Object o) {        return o instanceof RollNo other && other.roll == roll;    }
    @Override    public int hashCode() {        return Objects.hash(roll);    }}
public class EqualsHashCodeDemo {    public static void main(String[] args) {        Set<RollNoOnlyEquals> broken = new HashSet<>();        broken.add(new RollNoOnlyEquals(21));        broken.add(new RollNoOnlyEquals(21));        System.out.println("equals only: size " + broken.size());
        Set<RollNo> fixed = new HashSet<>();        fixed.add(new RollNo(21));        fixed.add(new RollNo(21));        System.out.println("equals and hashCode: size " + fixed.size());    }}
Output
equals only: size 2
equals and hashCode: size 1

What this code does

  • Without hashCode, the two equal objects almost always get different hash codes, land in different buckets, and equals is never even called.
  • The contract: equal objects must have equal hash codes. Unequal objects may share one; that only costs speed.
  • o instanceof RollNo other is pattern matching for instanceof (Java 16), which tests the type and casts in one step.

Answer in this shape: definition, why it matters, one example, in 2 to 4 sentences.

  • Name the follow-up yourself if you know it.
  • Not sure? Say what you do know and reason; never bluff.
  • Mark each answer correct, partly or wrong; partly and wrong go on the fix list.

Revise: The equals() method (opens in a new tab) and String immutability questions (opens in a new tab). Say each answer aloud before you open the model answer on the Interview tab.

Fix the error

Fix the equals method

Read the real compiler error, then pick the line that fixes it.

Round 1 of 2

A Student should be equal to another Student with the same roll number.

class Student {
int roll;
@Override
public boolean equals(Object o) {
return o.roll == roll;
}
}

Error

Student.java:5: error: cannot find symbol
        return o.roll == roll;
                ^
  symbol:   variable roll

Predict-the-output round

A predict-the-output question shows a few lines of Java and asks what they print and why. The reason ("== compares references, and new String makes a new object") carries most of the marks.

Example 4 packs six classic traps into one program. Trace it line by line, writing each variable's value as it changes, before you read the output.

Example 4 · Six classic output traps in one program

OutputRoundDemo.javaJava
class Parent {    static String kind() {        return "Parent static";    }
    String name() {        return "Parent";    }}
class Child extends Parent {    static String kind() {        return "Child static";    }
    @Override    String name() {        return "Child";    }}
public class OutputRoundDemo {    static int f() {        try {            return 1;        } finally {            System.out.println("finally runs");        }    }
    public static void main(String[] args) {        String a = "java";        String b = new String("java");        System.out.println((a == b) + " " + a.equals(b) + " " + (a == b.intern()));        System.out.println(7 / 2 + " " + 7 % 3 + " " + 7 / 2.0);        System.out.println('a' + 1 + "b" + 'c' + 1);        Parent p = new Child();        System.out.println(p.name() + ", " + p.kind());        System.out.println(f());        int i = 5;        i = i++ + ++i;        System.out.println(i);    }}
Output
false true true
3 1 3.5
98bc1
Child, Parent static
finally runs
1
12

What this code does

  • Line 3: 'a' + 1 is int arithmetic (97 + 1 = 98) because no String has appeared yet; after "b" everything is string joining.
  • Line 4: name() is overridden, so the object's real type (Child) decides; kind() is static, so the declared type (Parent) decides. That is method hiding, not overriding.
  • Last line: i++ gives 5 and makes i 6, then ++i makes it 7 and gives 7, so i becomes 5 + 7 = 12.

The traps interviewers reuse:

  • Strings: == versus equals, the string pool, intern().
  • Arithmetic: integer division, %, char + int, left-to-right + with strings.
  • OOP: overriding is decided at run time, static methods by the declared type.
  • Flow: finally runs before a return completes; i++ versus ++i.

Revise: String equality puzzles (opens in a new tab).

Predict the output

Predict the traps

Work out what each snippet prints.

Round 1 of 3

Two strings with the same text.

String x = "java";
String y = new String("java");
System.out.println(x == y);

The coding problem with narration

Narration is saying what you are doing while you solve a problem: restate it, ask about edge cases, give the brute force, improve it, code, then dry run. Silence hides your thinking from the interviewer.

The mock problem is First Unique Character: return the index of the first character that appears exactly once, or -1. Example 5 is the O(n) solution with its test inputs.

Example 5 · Coding problem: First Unique Character

FirstUniqueCharDemo.javaJava
import java.util.HashMap;import java.util.Map;
public class FirstUniqueCharDemo {    // Index of the first character that appears exactly once, or -1.    // O(n) time, O(k) extra space for k distinct characters.    static int firstUnique(String s) {        Map<Character, Integer> counts = new HashMap<>();        for (char ch : s.toCharArray()) {            counts.merge(ch, 1, Integer::sum);        }        for (int i = 0; i < s.length(); i++) {            if (counts.get(s.charAt(i)) == 1) {                return i;            }        }        return -1;    }
    public static void main(String[] args) {        String[] tests = {"swiss", "racecar", "placement", "aabb", ""};        for (String t : tests) {            System.out.println("\"" + t + "\" -> " + firstUnique(t));        }    }}
Output
"swiss" -> 1
"racecar" -> 3
"placement" -> 0
"aabb" -> -1
"" -> -1

What this code does

  • Pass 1 counts every character; pass 2 walks the string in its own order, so the first count of 1 found is the first unique character.
  • counts.get(...) == 1 compares an Integer with an int, so Java unboxes and compares values; that is safe, unlike == between two Integer objects.
  • The tests include the edge cases you should mention while clarifying: no unique character ("aabb") and an empty string.

The brute force compares every character with every other one: O(n²). Counting first, then scanning again, is O(n) time with a small map.

  • Clarify: empty string? Only lowercase letters? Return the index or the character?
  • Say the brute force first, then the improvement.
  • Finish with a dry run on "swiss", then O(n) time and O(k) space for k distinct characters.

Revise: Clarifying questions and edge cases (opens in a new tab).

Find the bug

Find the bug in the solution

Tap the line with the bug, as a reviewer would.

The loop finds the first unique character, but the answers are off by one.

Round 1 of 3

Live-coding twice: on a shared screen and on paper

A dry run is tracing your code by hand on a small input, writing down each variable's value after every line, so you find bugs before the interviewer does.

Do the coding part twice with a different problem each time: typed on a shared screen, then written by hand on paper, 15 minutes each. Example 6 is the paper run and a comparison sheet.

  1. Before the timer: close other apps, turn notifications off, raise the editor font, open a blank Main.java with a main method.
  2. Share only the editor window and confirm the interviewer can read it.
  3. Restate the problem and type two example inputs as comments at the top.
  4. Say the approach and its complexity, then type in small pieces, talking as you go.
  5. Run often with your own inputs in main; read any error message aloud before fixing it.
  6. At 15 minutes stop, state the complexity and note what you would test next.

Example 6 · The paper run and the comparison sheet

Text
PAPER RUN (15 minutes, problem: Reverse the Words in a Sentence)  1. Write the problem in one line and two examples, including "  extra   spaces ".  2. Write the method signature top-left; leave space between lines for fixes.  3. Say the approach: split on "\\s+" after strip(), walk backwards, join.  4. Write the code slowly and neatly; exact Java: String[], .length, .length().  5. Dry run with a small table: index, word, result so far.  6. Check edge cases out loud: empty string, one word, many spaces.COMPARE THE TWO RUNS                    Screen run        Paper run  Finished in       ___ min           ___ min  Talked while      yes / partly / no yes / partly / no  Syntax errors     ___ (compiler)    ___ (found by you)  Tested edges      ___ of 3          ___ of 3  Fix next time     ________________  ________________
Plan
Two problems, two setups, 15 minutes each, one comparison sheet

What this code does

  • On paper there is no compiler, so the dry run table is how you find bugs before the interviewer does.
  • Common paper slips are length versus length() and missing generics; interviewers forgive small slips if your logic and testing are clear.
  • Comparing the two runs shows which setup needs more practice before your real rounds.

The two setups fail differently: on screen people stop talking while typing; on paper they forget exact syntax and never test.

Revise: Live coding on a shared screen (opens in a new tab) and Whiteboard coding and dry runs (opens in a new tab). Practise under time: Mock Interview Mode (opens in a new tab) draws questions from all the interview banks, you answer aloud and rate yourself.

Order of execution

Order a screen run

Tap the steps in the order a strong candidate takes them.

Next step

Check your understanding

12 quick questions