OOP Basics • Strings and Keywords • Simple Programs • Exceptions • Threads • 2026

Java Interview Questions for Freshers

Java interviews for freshers usually test whether you can explain the basics in your own words: OOP, strings, the common keywords, collections you use every day, exceptions and simple threads. Then comes a small program on a whiteboard and a few questions about what you built in college. It is written for final-year students, new graduates and anyone coming out of an internship or a bootcamp who is facing a first Java interview. Each question shows what the interviewer is checking, the shape of a good answer and a short answer you can say out loud. Practice the programs by hand, then swap the project stories for your own.

Search all questions by round, difficulty and level, or save the ones you want to practice.

OOP Basics 5 questions

Easy Technical round Fresher Practice question

1. Explain the four pillars of object-oriented programming using a class from a project you built.

What the interviewer is really testing:
Whether you understand encapsulation, inheritance, polymorphism and abstraction well enough to point at them in real code, not just recite definitions.
Answer frame:

Pick one example: a class from your own project, named up front.

Walk the four: encapsulation, inheritance, polymorphism, abstraction, each tied to that example.

Why it helped: one line on what the design made easier.

Sample spoken answer:

“In my library management project I had an abstract class called Member. Encapsulation: the fine balance was a private field, and the only way to change it was through methods like addFine and payFine, so nobody could set it to a negative number. Inheritance: Student and Faculty both extended Member and reused its code. Polymorphism: each subclass overrode getBorrowLimit, so when the checkout code called member.getBorrowLimit it got the right number without checking the type. Abstraction: the checkout screen only knew about Member and its public methods, not how each type worked inside. The nice part was that when we added a Guest member late in the project, the checkout code didn't change at all.”

Red flag to avoid:

Reciting textbook definitions with no example, or mixing up abstraction and encapsulation.

They may ask next:
  • Which of the four is achieved by a private field plus public methods?
  • Is method overloading an example of polymorphism?
Say it in 60 seconds
Easy Technical round Fresher Practice question

2. What is a constructor, and how do this() and super() work when one constructor calls another?

What the interviewer is really testing:
Whether you know how objects are set up, what the default constructor is, and the order in which parent and child constructors run.
Answer frame:

Constructor: same name as the class, no return type, runs on new.

this(): calls another constructor in the same class.

super(): calls the parent's constructor, so the parent part is built first; classically it's the first line.

Sample spoken answer:

“A constructor is a special block with the same name as the class and no return type, and it runs when I write new to set up the object's starting state. If I don't write any, Java gives me a default no-argument one, but only if I've written none at all. this() lets one constructor call another in the same class, which avoids repeating code: a two-argument constructor can pass a default value to the three-argument one. super() calls the parent class's constructor. If I don't write it, Java inserts a call to the parent's no-argument constructor for me, so the parent part of the object is always built before the child part. Traditionally both this() and super() have to be the first statement, so you can't use both in one constructor.”

Code:
class Account {
    String owner;
    double balance;

    Account(String owner) {
        this(owner, 0.0); // reuse the other constructor
    }

    Account(String owner, double balance) {
        this.owner = owner;
        this.balance = balance;
    }
}
Red flag to avoid:

Giving a constructor a return type, or not knowing that the parent constructor runs first.

They may ask next:
  • What happens if the parent class has only a constructor that takes arguments?
  • Can a constructor be private? Why would you do that?
Say it in 60 seconds
Easy Technical round Fresher Practice question

3. Explain the four access levels in Java: public, protected, default and private. Where can each one be seen?

What the interviewer is really testing:
Whether you know the visibility rules, especially the often-forgotten package-private default and what protected really allows.
Answer frame:

private: inside the same class only.

default (no keyword): anywhere in the same package.

protected: same package, plus subclasses in other packages.

public: everywhere.

Sample spoken answer:

“From tightest to loosest: private means only code inside the same class can see it, which is what I use for fields. Default, which is what you get when you write no modifier at all, means anything in the same package can see it; people call it package-private. protected includes the same package and also subclasses, even when they're in a different package. public means any class anywhere can use it. My rule in college projects was to make fields private and expose only the methods other classes really needed. A detail that surprises people is that protected is actually wider than default, not narrower, because it adds subclasses on top of the package.”

Red flag to avoid:

Thinking default means public, or that protected is only visible to subclasses.

They may ask next:
  • Can a top-level class be private or protected?
  • When you override a method, can you make it less visible than the parent's version?
Say it in 60 seconds
Hard Technical round Fresher, Mid-level Practice question

4. Why doesn't Java allow a class to extend two classes? And what happens if two interfaces give you the same default method?

What the interviewer is really testing:
Whether you understand the diamond problem and how Java resolves the same clash when it shows up through interfaces.
Answer frame:

Diamond problem: two parents with the same method, which one does the child get?

Java's choice: one parent class, many interfaces.

Default clash: the compiler forces the class to override and pick, using InterfaceName.super.

Sample spoken answer:

“If a class could extend two classes that both define the same method, or both carry state, it would be unclear which version the child inherits. That's the diamond problem, and Java avoids it by allowing only one parent class. A class can implement many interfaces, and for a long time that was safe because interfaces had no method bodies. Default methods brought the clash back: if two interfaces both give a default hello method, a class implementing both won't compile until it overrides hello itself. Inside that override it can pick one side with First.super.hello(), or combine both. Also, if a parent class already has a hello method, the class's version wins over any interface default.”

Code:
interface First  { default String hello() { return "first"; } }
interface Second { default String hello() { return "second"; } }

class Both implements First, Second {
    @Override
    public String hello() {
        return First.super.hello(); // must choose explicitly
    }
}
Red flag to avoid:

Saying interfaces give full multiple inheritance with no conflicts, or not knowing the code fails to compile.

They may ask next:
  • Can an interface have a static method? How do you call it?
  • What changes if Second extends First and overrides hello itself?
Say it in 60 seconds
Hard Technical round Fresher, Mid-level Practice question

5. What is the difference between a shallow copy and a deep copy of an object? How would you make a deep copy in Java?

What the interviewer is really testing:
Whether you understand that copying an object copies references to its inner objects unless you do more work, and why that causes shared-state bugs.
Answer frame:
Shallow vs Deep
Shallowa new outer object whose fields still point to the same inner objects.
Deepthe inner mutable objects are copied too, so nothing is shared.

How: a copy constructor that copies each mutable field; be careful with clone.

Sample spoken answer:

“A shallow copy creates a new outer object but copies each field as it is, so if a field is a reference to a list, both copies point to the same list. Add a mark to one student's list and the other student's list changes too. A deep copy also copies the inner mutable objects, so the two are fully independent. Object's clone method does a shallow copy by default, and it only works if the class implements Cloneable, otherwise it throws CloneNotSupportedException, which makes it awkward. I'd rather write a copy constructor that creates a new list with the same elements. Immutable fields like Strings can be shared safely, so only the mutable ones need copying.”

Code:
class Student {
    String name;
    List<Integer> marks;

    Student(String name, List<Integer> marks) {
        this.name = name;
        this.marks = new ArrayList<>(marks);
    }

    Student(Student other) {             // deep copy
        this.name = other.name;          // String is immutable, safe to share
        this.marks = new ArrayList<>(other.marks);
    }
}
Red flag to avoid:

Thinking assignment (b = a) makes a copy, or that clone always makes a deep copy.

They may ask next:
  • If the list held Address objects instead of Integers, is new ArrayList enough for a deep copy?
  • Why are immutable objects easier to copy?
Say it in 60 seconds

Java Basics 4 questions

Easy Technical round Fresher Practice question

6. Why do people call Java platform independent? What is bytecode, and who actually runs it?

What the interviewer is really testing:
Whether you know the compile-then-run path of a Java program and can say what 'write once, run anywhere' really means.
Answer frame:

Compile: javac turns .java source into .class files holding bytecode.

Run: a JVM built for each operating system reads that same bytecode.

Catch: the program is portable; the JVM itself is not.

Sample spoken answer:

“When I compile a Java file with javac, it doesn't produce machine code for my laptop. It produces a .class file full of bytecode, which is a set of instructions for the Java Virtual Machine rather than for a real processor. Every operating system has its own JVM, and each one knows how to run that same bytecode, interpreting it and compiling the hot parts to native code as it goes. So I can compile on Windows and run the same .class file on Linux or a Mac without changing anything. That's what platform independent means. The small catch is that the JVM itself is platform dependent: you install a different one for each system, which is exactly what lets the program stay the same.”

Red flag to avoid:

Saying the JVM is platform independent, or that javac produces an executable for the current machine.

They may ask next:
  • What is the JIT compiler, and why does it make Java faster than pure interpretation?
  • Is C platform independent in the same way? Why not?
Say it in 60 seconds
Easy Technical round Fresher Practice question

7. Explain every word in public static void main(String[] args). Why does main need to be static?

What the interviewer is really testing:
Whether you understand what each keyword means in the most familiar line of Java, rather than typing it from memory.
Answer frame:

Word by word: public, static, void, main, String[] args.

Why static: the JVM calls it before any object exists.

args: the command-line arguments, as an array of strings.

Sample spoken answer:

“public means the JVM, which sits outside my class, is allowed to call it. static means the method belongs to the class, not to an object, so the JVM can call it without first creating an instance. void means it returns nothing to the caller. main is simply the name the launcher looks for as the starting point. And String[] args holds whatever I type after the class name on the command line, so java App hello world gives me an array of two strings. In the classic form, static is needed because at the moment the program starts, no object of my class exists yet. Newer Java releases also accept a simpler main method, but interviewers usually mean this classic version.”

Code:
public class App {
    public static void main(String[] args) {
        System.out.println("Got " + args.length + " arguments");
    }
}
Red flag to avoid:

Saying static means the value can't change, or not knowing what args contains.

They may ask next:
  • Can you overload the main method? Which one does the JVM call?
  • What happens if you run a class that has no main method?
Say it in 60 seconds
Hard Technical round Fresher, Mid-level Practice question

8. Is Java pass-by-value or pass-by-reference? If a method changes an object's field, why does the caller see it?

What the interviewer is really testing:
Whether you can explain that Java copies the reference, and predict what happens when a method reassigns versus modifies a parameter.
Answer frame:

Rule: Java is always pass-by-value.

With objects: the value copied is the reference, so both point to the same object.

Proof: changing a field shows up; reassigning the parameter doesn't.

Sample spoken answer:

“Java is always pass-by-value. With a primitive, the method gets a copy of the number, so changing it inside the method doesn't affect the caller. With an object, the variable holds a reference, and it's that reference that gets copied. So the method's parameter and the caller's variable point to the same object. If the method changes a field through that reference, the caller sees the change, which is why people think it's pass-by-reference. But if the method reassigns the parameter to a new object, only its local copy moves; the caller's variable still points to the original. In this example the dog ends up called Max, not Rex. With true pass-by-reference, the reassignment would have changed the caller too.”

Code:
class Dog {
    String name;
    Dog(String name) { this.name = name; }
}

static void rename(Dog d) {
    d.name = "Max";     // caller sees this
    d = new Dog("Rex"); // caller does not
}

// Dog pet = new Dog("Tom");
// rename(pet);
// pet.name is now "Max"
Red flag to avoid:

Saying objects are passed by reference and primitives by value, without being able to explain the reassignment case.

They may ask next:
  • Can you write a swap method that swaps two Integer variables in the caller? Why not?
  • What happens if you pass a String and change it inside the method?
Say it in 60 seconds
Medium Technical round Fresher, Mid-level Practice question

9. What are wrapper classes and autoboxing? Why can two Integer values of 1000 give false with == but two of 100 give true?

What the interviewer is really testing:
Whether you know why wrapper types exist, what the compiler does behind autoboxing, and the Integer cache trap.
Answer frame:

Wrappers: object versions of primitives, needed for collections and null.

Autoboxing: the compiler converts between int and Integer for you.

The trap: small values come from a cache, big ones are new objects, so == is unreliable.

Sample spoken answer:

“Every primitive has a wrapper class, like int and Integer or double and Double. We need them because collections only hold objects, so a List can't store a plain int, and because a wrapper can be null. Autoboxing is the compiler turning an int into an Integer for me, using Integer.valueOf, and unboxing is the reverse. The == puzzle comes from that valueOf call: Java caches Integer objects from minus 128 to 127, so two boxed 100s are literally the same object and == is true. Two boxed 1000s are usually separate objects, so == compares references and gives false. The fix is simple: compare wrapper objects with equals, or unbox to int first. Also, unboxing a null Integer throws a NullPointerException.”

Code:
Integer a = 100, b = 100;
Integer c = 1000, d = 1000;
System.out.println(a == b);      // true: cached object
System.out.println(c == d);      // false: two objects
System.out.println(c.equals(d)); // true
Red flag to avoid:

Saying == on Integer always compares values, or not knowing wrappers can be null.

They may ask next:
  • What happens if you unbox a null Integer?
  • Why is list.remove(1) on a List of Integer a common trap?
Say it in 60 seconds

Strings 2 questions

Easy Technical round Fresher Practice question

10. When comparing two Strings, what is the difference between using == and using equals()?

What the interviewer is really testing:
Whether you know the difference between comparing references and comparing content, the source of many beginner bugs.
Answer frame:
== vs equals()
==checks whether both variables point to the same object.
equals()checks whether the characters are the same.

Trap: literals often share one object, so == can seem to work until it doesn't.

Sample spoken answer:

“== compares references: it's true only if both variables point to the exact same object in memory. equals, on a String, compares the actual characters. The confusing part is that two identical string literals usually point to the same object because of the string pool, so == happens to return true and the bug hides. But if one string comes from new String, from user input or from joining strings at run time, it's a different object, and == returns false even though the text is the same. So for comparing text I always use equals, or equalsIgnoreCase when case doesn't matter. I also write "yes".equals(input) with the literal first, so a null input just gives false instead of a NullPointerException.”

Code:
String a = "java";
String b = new String("java");
System.out.println(a == b);      // false: different objects
System.out.println(a.equals(b)); // true: same characters
Red flag to avoid:

Saying == compares values for Strings, or that equals and == are the same thing.

They may ask next:
  • What does the intern method do?
  • Why does "yes".equals(input) avoid a NullPointerException?
Say it in 60 seconds
Easy Technical round Fresher, Mid-level Practice question

11. What is the difference between String, StringBuilder and StringBuffer, and which one would you use to build a long string in a loop?

What the interviewer is really testing:
Whether you know mutable versus immutable text and why string concatenation inside a loop is wasteful.
Answer frame:
String vs StringBuilder vs StringBuffer
Stringimmutable, every change makes a new object.
StringBuildermutable, fast, not synchronized.
StringBuffermutable and synchronized, rarely needed today.
Sample spoken answer:

“A String can't change once it's created, so every time I write s = s + something inside a loop, Java builds a brand new String and copies all the old characters into it. In a loop of thousands of iterations that's a lot of copying and garbage. StringBuilder holds a growable buffer of characters that I change in place with append, so it's the one I use to build a long string. StringBuffer does the same job but its methods are synchronized, which makes it safe to share between threads but a bit slower. In practice I almost never share a string being built across threads, so I pick StringBuilder, and I call toString once at the end.”

Code:
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= 5; i++) {
    sb.append(i).append(',');
}
String result = sb.toString(); // "1,2,3,4,5,"
Red flag to avoid:

Saying StringBuilder is thread-safe, or not knowing that String is immutable.

They may ask next:
  • Is a single line like "Hello " + name slow? Why or why not?
  • How would you reverse a string using StringBuilder?
Say it in 60 seconds

Keywords 2 questions

Easy Technical round Fresher Practice question

12. What does the static keyword mean on a variable, on a method and on a block of code?

What the interviewer is really testing:
Whether you understand class-level versus object-level members and the rules that follow from it.
Answer frame:

Static variable: one copy shared by every object of the class.

Static method: called on the class, can't use this or instance fields directly.

Static block: runs once when the class is initialised.

Sample spoken answer:

“static means the thing belongs to the class, not to any one object. A static variable has a single copy that all objects share, so if I keep a counter of how many Student objects were created, I make it static and every constructor increments the same number. A static method is called on the class name, like Math.max, and because there's no object involved it can't use this or touch instance fields directly. A static block is code that runs once, when the class is first initialised, before any object is created, so it's a place to set up static data like a lookup table. The common mistake is making things static just to call them from main, which ends up turning everything into global state.”

Code:
class Student {
    static int count = 0;   // shared by all students
    String name;            // one per student

    Student(String name) {
        this.name = name;
        count++;
    }
}
Red flag to avoid:

Saying static means the value can't be changed, which is what final does.

They may ask next:
  • Can a static method call a non-static method of the same class?
  • Can you override a static method?
Say it in 60 seconds
Easy Technical round Fresher Practice question

13. What is the difference between final, finally and finalize in Java?

What the interviewer is really testing:
Whether you can keep three similar-sounding words apart and know that one of them is outdated.
Answer frame:
final vs finally vs finalize
finala keyword for variables, methods and classes that can't be changed, overridden or extended.
finallya block after try that runs whether or not an exception happened.
finalizean old cleanup method, deprecated, not to be relied on.
Sample spoken answer:

“They sound alike but do completely different jobs. final is a keyword: a final variable can be assigned only once, a final method can't be overridden, and a final class, like String, can't be extended. finally is a block that goes with try and catch; it runs whether the try finishes normally or throws, so it's where I used to close files or database connections. finalize is a method on Object that the garbage collector might call before reclaiming an object. It was never guaranteed to run at a predictable time, and it's now deprecated, so I wouldn't use it. For cleanup I use try-with-resources instead. One detail people miss: a final reference to a list stops me reassigning the variable, but I can still add items to the list.”

Red flag to avoid:

Saying finalize is the right place to release resources, or that final makes an object immutable.

They may ask next:
  • If a variable holding an ArrayList is final, can you add elements to it?
  • Why is String declared as a final class?
Say it in 60 seconds

Simple Programs 4 questions

Easy Coding round Fresher Practice question

14. Write a Java method that checks whether a string is a palindrome, without using a built-in reverse.

What the interviewer is really testing:
Whether you can write a clean loop with two indexes, think about edge cases and state the cost.
Answer frame:

Approach: two pointers, one from each end, moving inward.

Stop early: return false on the first mismatch.

Edges and cost: empty string, case, spaces; O(n) time, O(1) extra space.

Sample spoken answer:

“I'd use two pointers. One starts at the first character and one at the last. While left is less than right, I compare the two characters; if they differ it's not a palindrome and I return false straight away. If they match, I move left forward and right back. If the pointers meet or cross without a mismatch, it's a palindrome. That's O(n) time and no extra space, because I never build a reversed copy. Before coding I'd ask whether case and spaces count. If the interviewer says 'Madam' should pass, I lower-case the string first, and for phrases I'd skip anything that isn't a letter or digit. An empty string or a single character counts as a palindrome and falls out of the loop naturally.”

Code:
static boolean isPalindrome(String s) {
    String t = s.toLowerCase();
    int left = 0, right = t.length() - 1;
    while (left < right) {
        if (t.charAt(left) != t.charAt(right)) {
            return false;
        }
        left++;
        right--;
    }
    return true;
}
Red flag to avoid:

Building a reversed string with += in a loop and not noticing the cost, or never testing an empty string.

They may ask next:
  • How would you change it to ignore spaces and punctuation, so 'A man, a plan' works?
  • How would you check whether a number is a palindrome without turning it into a string?
Say it in 60 seconds
Easy Coding round Fresher Practice question

15. Given an array of integers, print each value that appears more than once. What is the time complexity of your approach?

What the interviewer is really testing:
Whether you move past the nested-loop answer to a set-based one and can compare the two.
Answer frame:

Brute force: two nested loops, O(n squared), mention it and move on.

Better: a HashSet of seen values; add returns false for a repeat.

Clean output: a second set so each duplicate prints once.

Sample spoken answer:

“The first idea is two nested loops comparing every pair, which works but is O(n squared). A better way is to walk the array once with a HashSet called seen. HashSet's add method returns false if the value is already there, so the moment add fails I know it's a repeat. To avoid printing a value three times when it appears three times, I keep a second set of duplicates and print that at the end. Both sets give average constant-time lookups, so the whole thing is O(n) time and O(n) extra space. If the interviewer says I can't use extra memory, I'd sort the array first and then compare neighbours, which is O(n log n) time.”

Code:
static Set<Integer> findDuplicates(int[] nums) {
    Set<Integer> seen = new HashSet<>();
    Set<Integer> dups = new LinkedHashSet<>();
    for (int n : nums) {
        if (!seen.add(n)) {
            dups.add(n);
        }
    }
    return dups;
}
Red flag to avoid:

Stopping at the nested-loop answer, or printing the same duplicate several times without noticing.

They may ask next:
  • How would you also print how many times each duplicate appears?
  • Why did you choose LinkedHashSet for the result?
Say it in 60 seconds
Medium Coding round Fresher Practice question

16. Write the Fibonacci series two ways, with recursion and with a loop. Which one would you actually use, and why?

What the interviewer is really testing:
Whether you can write recursion with a correct base case and explain why naive recursion is slow compared with a loop.
Answer frame:

Recursive: base cases for 0 and 1, then fib(n-1) plus fib(n-2).

Loop: keep only the last two numbers.

Cost: recursion repeats work and grows exponentially; the loop is O(n).

Sample spoken answer:

“The recursive version reads just like the definition: if n is 0 or 1, return n, otherwise return fib of n minus 1 plus fib of n minus 2. It's short, but it recomputes the same values again and again, so the number of calls grows exponentially, and for large n it can also overflow the stack. The loop version keeps two variables, the previous two numbers, and slides them forward n times, so it's O(n) time and constant space. That's the one I'd use. If the interviewer wants recursion anyway, I'd add memoization, storing each result in an array so each value is computed once. I'd also mention that int overflows fairly early, so for bigger n I'd switch to long or BigInteger.”

Code:
static int fibRecursive(int n) {
    if (n <= 1) return n;
    return fibRecursive(n - 1) + fibRecursive(n - 2);
}

static long fibLoop(int n) {
    long prev = 0, curr = 1;
    if (n == 0) return 0;
    for (int i = 2; i <= n; i++) {
        long next = prev + curr;
        prev = curr;
        curr = next;
    }
    return curr;
}
Red flag to avoid:

A recursive version with no base case, or claiming the naive recursion is as fast as the loop.

They may ask next:
  • How would memoization change the time complexity of the recursive version?
  • What happens if you call the recursive version with a very large n?
Say it in 60 seconds
Medium Coding round Fresher Practice question

17. Find the second largest number in an integer array in a single pass, without sorting it.

What the interviewer is really testing:
Whether you can track two values carefully and handle the edge cases a strong fresher thinks of: duplicates and arrays that are too small.
Answer frame:

Track two: largest and second, both starting at the smallest possible value.

Update rule: a new largest pushes the old one down to second.

Edges: repeated maximums, fewer than two distinct values.

Sample spoken answer:

“I keep two trackers, largest and second. In the code they're long values starting at Long.MIN_VALUE, so even Integer.MIN_VALUE in the array counts as a real number. For each number, if it's bigger than largest, the old largest drops to second and the number becomes largest. Otherwise, if it's bigger than second and not equal to largest, it becomes the new second. I'd first ask whether they mean the second largest distinct value; usually they do, so in 9, 9, 4 the answer is 4, and the not-equal check handles that. It's one pass, O(n) time and constant space, which beats sorting at O(n log n). If second was never updated, there's no answer, for example with one element or all values equal, so I return an empty OptionalInt instead of a misleading number.”

Code:
static OptionalInt secondLargest(int[] nums) {
    long largest = Long.MIN_VALUE, second = Long.MIN_VALUE;
    for (int n : nums) {
        if (n > largest) {
            second = largest;
            largest = n;
        } else if (n > second && n != largest) {
            second = n;
        }
    }
    return second == Long.MIN_VALUE ? OptionalInt.empty() : OptionalInt.of((int) second);
}
Red flag to avoid:

Sorting and taking the second-last element, which fails when the largest value repeats.

They may ask next:
  • Why did the code use long for the trackers instead of int?
  • How would you find the k-th largest number?
Say it in 60 seconds

Collections 2 questions

Easy Technical round Fresher Practice question

18. When would you use a List, a Set or a Map? Give one real use of each from something you've built.

What the interviewer is really testing:
Whether you choose collections by what the data needs, order, uniqueness or lookup by key, rather than using ArrayList for everything.
Answer frame:

List: ordered, allows duplicates, access by position.

Set: no duplicates, fast contains.

Map: key to value, look up by key.

Project example: one use of each, briefly.

Sample spoken answer:

“I pick based on what the data needs. A List keeps things in order and allows duplicates, so in my quiz app the questions for a test were an ArrayList, because order mattered and I read them by index. A Set doesn't allow duplicates and answers contains quickly, so I used a HashSet of question ids a student had already attempted, to avoid showing one twice. A Map stores key-value pairs, so scores were a HashMap from student id to their total, which let me update one student's score directly instead of searching a list. If I needed the keys sorted, say for a leaderboard by name, I'd switch to a TreeMap, and LinkedHashMap if I wanted insertion order.”

Red flag to avoid:

Using a List and calling contains inside a loop where a Set was the obvious fit.

They may ask next:
  • Which Set would you use if you needed the elements in sorted order?
  • Can a HashMap have a null key?
Say it in 60 seconds
Medium Technical round Fresher, Mid-level Practice question

19. What is the difference between Comparable and Comparator? Show how you would sort a list of students by marks.

What the interviewer is really testing:
Whether you know natural ordering versus custom ordering and can write a sort with modern Comparator methods.
Answer frame:
Comparable vs Comparator
Comparablethe class defines its one natural order with compareTo.
Comparatora separate object that defines any order you want.

Code: Comparator.comparing, with thenComparing and reversed.

Sample spoken answer:

“Comparable is implemented by the class itself: Student implements Comparable and writes compareTo, which gives it one natural order, say by roll number. Then Collections.sort on a list of students uses that order. Comparator is a separate object that describes an order from the outside, so I can have as many as I like, by marks, by name, by marks then name, without touching the Student class. That also works for classes I can't edit. In modern Java I build comparators with Comparator.comparing, so sorting by marks highest first, then by name, is one readable line. When writing compareTo by hand I use Integer.compare rather than subtracting two numbers, because subtraction can overflow and give the wrong sign.”

Code:
record Student(String name, int marks) {}

List<Student> list = new ArrayList<>(students);
list.sort(Comparator.comparingInt(Student::marks)
        .reversed()
        .thenComparing(Student::name));
Red flag to avoid:

Mixing up which one uses compareTo and which uses compare, or not knowing you can have many Comparators.

They may ask next:
  • Why is returning a - b from compareTo risky?
  • What happens if you add objects that aren't Comparable to a TreeSet with no Comparator?
Say it in 60 seconds

Exceptions 2 questions

Medium Technical round Fresher Practice question

20. What is the difference between throw and throws, and what happens to an exception that nobody catches?

What the interviewer is really testing:
Whether you understand how exceptions travel up the call stack and the difference between raising one and declaring one.
Answer frame:
throw vs throws
throwa statement that raises one exception object right now.
throwspart of a method signature, warning callers what may come out.

Uncaught: it climbs the call stack; if it reaches the top, the thread ends with a stack trace.

Sample spoken answer:

“throw is an action: inside a method I write throw new IllegalArgumentException with a message, and that exception starts travelling immediately. throws is a declaration in the method signature, like throws IOException, telling callers this method might pass that exception up to them, and for checked exceptions the compiler makes them handle it or declare it too. When an exception is thrown and not caught, Java looks up the call stack: the current method ends, then its caller, and so on, until some method has a matching catch. If none does and it reaches the top of the thread, in a simple program that's main, the thread ends and the stack trace is printed. In a console program that means the program crashes with that trace.”

Code:
static int parseAge(String text) throws NumberFormatException {
    int age = Integer.parseInt(text);
    if (age < 0) {
        throw new IllegalArgumentException("Age can't be negative: " + age);
    }
    return age;
}
Red flag to avoid:

Treating throw and throws as the same keyword, or thinking an uncaught exception is silently ignored.

They may ask next:
  • Can a catch block catch an exception and throw a different one? Why would you do that?
  • What order should catch blocks go in when one exception type extends another?
Say it in 60 seconds
Easy Technical round Fresher Practice question

21. What causes a NullPointerException, and what habits in your own code help you avoid it?

What the interviewer is really testing:
Whether you know what null means and have practical habits, not just 'add a null check everywhere'.
Answer frame:

Cause: calling a method or reading a field through a reference that is null.

Reading it: the stack trace line, and the helpful message newer Java versions print.

Habits: initialise fields, return empty collections, check inputs early.

Sample spoken answer:

“A NullPointerException happens when I use a reference that points to nothing: calling a method on it, reading a field, taking the length of a null array, or unboxing a null Integer. When I hit one, I start with the line in the stack trace, and newer Java versions even say which variable was null. To avoid them, I initialise fields when I declare them, for example a list starts as an empty ArrayList instead of null. Methods that return collections return an empty list rather than null, so callers can loop safely. I check parameters at the start of a method with Objects.requireNonNull, so the error appears where the bad value came in, not three calls later. And for string comparisons I put the literal first.”

Red flag to avoid:

Saying the fix is to wrap code in try-catch for NullPointerException.

They may ask next:
  • Where does a NullPointerException come from when you write int x = map.get(key); and the key is missing?
  • Why is failing early with requireNonNull better than failing later?
Say it in 60 seconds

Threads 1 question

Medium Technical round Fresher Practice question

22. What are the ways to create a thread in Java, and what is the difference between calling start() and calling run()?

What the interviewer is really testing:
Whether you know Runnable versus extending Thread and the classic beginner mistake of calling run directly.
Answer frame:

Two basic ways: extend Thread, or pass a Runnable (often a lambda) to a Thread.

Prefer Runnable: keeps your class free to extend something else and separates the task from the thread.

start vs run: start makes a new thread; run just calls a method on the current one.

Sample spoken answer:

“The two basic ways are extending Thread and overriding run, or writing a Runnable and passing it to a new Thread. I prefer Runnable, usually as a lambda, because Java only allows one parent class, and it keeps the task separate from the thread that runs it. In real code I'd hand tasks to an executor rather than making threads by hand. The start versus run difference is a classic trap. start asks the JVM to create a new thread, and that new thread calls run. If I call run directly, no new thread is created; the code just runs on the current thread like any normal method call. Also, a thread can be started only once. Calling start a second time throws IllegalThreadStateException.”

Code:
Runnable task = () ->
    System.out.println("Running on " + Thread.currentThread().getName());

Thread t = new Thread(task);
t.start(); // runs on a new thread
task.run(); // runs on the current thread
Red flag to avoid:

Saying run() and start() do the same thing, or not knowing that calling run() creates no new thread.

They may ask next:
  • What does join() do?
  • What is the difference between Runnable and Callable?
Say it in 60 seconds

Your Projects 2 questions

Medium Behavioral round Fresher Practice question

23. Pick one Java project on your resume. Which classes did you write, why did you design them that way, and what would you change today?

What the interviewer is really testing:
Whether you really wrote the code you list on your resume, can explain your design choices, and can look back on your own work honestly.
Answer frame:

The project: what it did and who used it, in two lines.

Your part: the classes or features you wrote, and one decision you made.

Looking back: one concrete thing you'd change and why.

Sample spoken answer:

“In my final year, three of us built an attendance system for our department in Java with a MySQL database. I wrote the part that marked attendance and produced the monthly report. I designed a small Student class and an AttendanceRecord class, and used a HashMap from student id to their records so the report didn't query the database once per student. The trickiest bug was duplicate entries when a teacher clicked submit twice, which I fixed with a unique constraint and a check before inserting. Looking back, I put SQL strings directly into the screen classes, which made testing hard. Now I'd move all database code into one data-access class and write unit tests for the report logic.”

Red flag to avoid:

Describing only what the team did, never 'I', or being unable to explain a class you claim to have written.

They may ask next:
  • Why did you choose a HashMap there instead of a List?
  • How did the three of you split the work and merge your code?
Say it in 60 seconds
Medium Behavioral round Fresher Practice question

24. Tell me about a bug in your college or internship Java code that took you a long time to find. How did you finally track it down?

What the interviewer is really testing:
Whether you debug with a method, using the stack trace, a debugger or small experiments, instead of changing code at random.
Answer frame:

The symptom: what went wrong and why it was confusing.

The method: stack trace, debugger, breakpoints, or cutting the problem down.

The lesson: the cause, the fix, and a habit you kept.

Sample spoken answer:

“In my internship I built a small dashboard that showed what share of support tickets each team closed on time. Almost every team showed zero, and one showed exactly a hundred. I assumed the database query was wrong and lost most of a day there. Then I stopped guessing, printed the raw counts, and they were correct. So I put a breakpoint on the line that did the maths: closedOnTime divided by total, times 100, all ints. Integer division threw away the fraction, so anything below one became zero before the multiply. I changed it to closedOnTime times 100.0 divided by total, and added a guard for teams with no tickets. Since then, whenever a number looks wrong, I check the types in the calculation first, and I write a small test with numbers I've worked out by hand.”

Red flag to avoid:

A story that ends with 'I rewrote it and it worked' with no idea what the cause was.

They may ask next:
  • What does a debugger let you do that print statements don't?
  • How would you write a test that would have caught this bug earlier?
Say it in 60 seconds
Were you asked something else? Share it A person checks every question before it goes on the site. No name is shown.
For the call itself

You practiced these. On the real call, ClapAssist helps with the rest.

ClapAssist is an AI interview assistant for Mac and Windows. It listens to the interview on your computer and shows you what to say, in short lines you can read while you talk. Your live interview audio and screen are never stored. Your resume and notes are saved to your account so the app fills them in on any computer. It stays out of screen share on every plan, including Free; only you can see it.

Download with 10 free minutes
Mac and Windows · Stays out of screen share · No card