Java Interview Questions for Freshers with Clear & Concise Answers (2026 Edition)
Jul 16, 2026 18 Min Read 471367 Views
(Last Updated)
You can think of any large tech companies right now, such as Amazon, Google, Netflix, and others. Each of these companies relies heavily on the Java programming language, which serves as the primary component in building their state-of-the-art software products and internal systems. The reason is Java’s stability, security, and ability to handle complex, scalable systems without crashing.
This updated collection of Java Interview Questions for Freshers now covers 98 questions with code answers, difficulty tags, a dedicated OOP section, a Collections top 10, and the exact questions asked at TCS, Infosys, and Wipro campus drives in 2025-26. Don’t worry if you are a fresher; recruiters don’t look for advanced-level skills, but they will absolutely check how strong your fundamentals are. So, without waiting any further, let’s begin.
Table of contents
- TL;DR Summary
- Java Interview Questions for Freshers
- What is Java?
- Why is Java platform independent?
- What is JVM?
- What is the difference between JDK, JRE, and JVM?
- What is the difference between a class and an object?
- What is object-oriented programming?
- What is inheritance?
- What is encapsulation?
- What is polymorphism?
- What are access modifiers?
- What are static variables and methods?
- What are final variables and methods?
- What is a constructor?
- What is an array?
- What are control structures in Java?
- What is exception handling?
- What is the difference between a private and a protected method in Java?
- What is the difference between a while loop and a do-while loop in Java?
- What is the difference between a static and non-static variable in Java?
- What are text blocks in Java?
- What is the difference between == and .equals() in Java?
- What are default and static methods in interfaces?
- What is the Optional class and why is it used?
- What are lambda expressions?
- What are the different types of exceptions in Java?
- What is the difference between a HashSet and a TreeSet?
- What is the role of the ClassLoader in Java?
- What is the difference between shallow copy and deep copy?
- What is the difference between String, StringBuilder, and StringBuffer in Java?
- What is the difference between an abstract class and an interface in Java?
- How does garbage collection work in Java?
- Provide an example of polymorphism.
- What is a daemon thread?
- How do you implement a bubble sort algorithm in Java?
- How do you implement a binary search algorithm in Java?
- What is a thread in Java? Provide an example of how to create a thread.
- Explain marker interfaces vs functional interfaces.
- What are records in Java, and why were they introduced?
- What is pattern matching for switch in Java?
- What are sealed classes in Java?
- What is the difference between Comparable and Comparator in Java?
- What is the difference between an ArrayList and a LinkedList in Java?
- What is method reference in Java, and how is it different from a lambda?
- What is type erasure in Java generics?
- What is a binary search tree? How can you implement one in Java?
- How do you implement a merge sort algorithm in Java?
- What is a deadlock in Java? How can you prevent it?
- How do you implement a quick sort algorithm in Java?
- What are virtual threads in Java?
- What is the difference between fail-fast and fail-safe iterators in Java?
- Java OOP Interview Questions for Freshers
- What are the four pillars of OOP in Java?
- What is abstraction, and how do you achieve it in Java?
- What is constructor overloading in Java?
- What is method overloading, and what rules govern it?
- What is method overriding, and what rules govern it?
- Why does Java not support multiple inheritance with classes?
- What is the "is-a" vs "has-a" relationship in OOP?
- What is the super keyword used for in Java?
- Java Collections Interview Questions — Top 10
- What is the Collections Framework in Java?
- What is the difference between List, Set, and Map in Java?
- How do you iterate over a Map in Java?
- How do you remove duplicates from a List in Java?
- What is the difference between HashMap and Hashtable?
- What is the difference between HashMap and TreeMap?
- What is the difference between Iterator and ListIterator in Java?
- What is the difference between Comparable and Comparator when sorting a collection?
- What are Java Streams, and how do they work with Collections?
- What is the difference between synchronized collections and concurrent collections?
- Scenario-Based and Practical Java Interview Questions
- You are building a login feature. How will you store user passwords securely in Java?
- Your program needs to sort millions of records quickly. Which sorting approach will you use?
- You receive a list of email addresses and need to validate them. How will you do it in Java?
- A program must read a very large file line by line without consuming too much memory. What is the solution?
- A team reports that your API crashes when it receives null values. How will you handle it?
- You must share data across different parts of a program, but global variables create conflicts. What will you do?
- You notice your program creates too many objects and memory usage is high. How will you handle this?
- A program must handle multiple users uploading files at the same time. How will you make it thread-safe?
- Your REST API must return data quickly, but database queries are slow. How will you improve performance?
- Your system processes payments and must not process the same transaction twice. How will you guarantee this?
- Java Interview Questions Asked at TCS, Infosys, Wipro Campus Drives
- Write a Java program to check if a string is a palindrome.
- Write a Java program to find the factorial of a number.
- Write a Java program to check whether a number is prime.
- Write a Java program to print the Fibonacci series up to n terms.
- Write a Java program to swap two numbers without using a third variable.
- Write a Java program to count the number of vowels in a string.
- Write a Java program to find the largest element in an array.
- Explain the difference between == and equals() for two String objects (a common Wipro follow-up).
- Write a Java program to reverse each word in a sentence.
- Explain how a HashMap works internally (a common Infosys technical-round question).
- Common Java Project Questions Asked in Fresher Interviews
- Can you explain your Java project and its purpose?
- Which core Java concepts did you apply in your project?
- How did you manage and store data in your project?
- How is a problem usually approached before writing code in Java?
- Why is breaking a problem into smaller parts important?
- What matters more while solving a Java problem: syntax or logic?
- How did you handle errors and invalid input in your project?
- How do you explain the execution flow of your Java project?
- What is considered first while designing a Java solution?
- How is clarity built when multiple solutions are possible for one problem?
- Java Interview Preparation Roadmap for Freshers
- Conclusion
- FAQs
- Do I need to learn advanced Java concepts as a fresher to clear interviews?
- How much coding practice is enough for Java interview preparation?
- Are scenario-based questions really asked in fresher interviews?
- What if I forget answers during the interview?
- Is project knowledge important even for freshers?
- How should I prepare from this blog effectively?
TL;DR Summary
- This blog covers complete Java interview preparation for freshers, including basics, core concepts, advanced topics, and real interview questions with answers.
- Helps you understand how Java works in real-world scenarios through practical, scenario-based questions and project explanations.
- Provides a clear preparation roadmap to build strong fundamentals, practice effectively, and improve your chances of cracking interviews.
More than 90% of Fortune 500 companies use Java in their software development processes.
88% of Oracle Java users are actively considering switching to a different Java provider.
Roughly 70% of organizations say that over half of their applications are built with Java or run on a Java Virtual Machine (JVM).

Java Interview Questions for Freshers
Let’s look into some of the basic questions asked in Java Interview Questions for Freshers rounds, each with a difficulty tag and a short code answer.
1. What is Java?
Difficulty: Easy
This is a frequently asked question in Java Interview Questions for Freshers rounds. Interviewers often circle back to this point in Java Interview Questions for Freshers follow-ups.
Java is a high-level, object-oriented programming language developed by Sun Microsystems in 1995. Source code is compiled into platform-neutral bytecode executed by the Java Virtual Machine (JVM), giving Java the famous “write once, run anywhere” promise. Visit Oracle’s official website to download the JDK.
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, Java");
}
}
2. Why is Java platform independent?
Difficulty: Easy
This comes up often across Java Interview Questions for Freshers interviews. Keep this answer crisp — it’s a favorite in Java Interview Questions for Freshers screening rounds.
javac compiles source files into .class bytecode. Because every OS with a JVM can interpret that bytecode, the same binary runs unchanged across Windows, macOS, Linux, and even Android.
javac Hello.java
java Hello
3. What is JVM?
Difficulty: Easy
Recruiters commonly include this in Java Interview Questions for Freshers checklists. Many candidates lose marks here, so revise this before any Java Interview Questions for Freshers round.
JVM stands for Java Virtual Machine. It is an abstract machine that provides the runtime environment in which Java programs execute, interpreting bytecode and translating it into machine-specific instructions.
java -version
- If you don’t know an answer, don’t stay silent — start with what you do know and think out loud; interviewers care more about your approach than a perfect answer.
-
Interviewer: “What is multithreading in Java?”
You: “I’m not fully sure about the full definition, but I know it allows running multiple tasks at the same time. I think it helps improve performance. For example, like when an app is doing background work while also responding to user actions.”
4. What is the difference between JDK, JRE, and JVM?
Difficulty: Easy
This is a staple entry in most Java Interview Questions for Freshers lists. Interviewers often circle back to this point in Java Interview Questions for Freshers follow-ups.
JDK (Java Development Kit) bundles the compiler, debugger, and JRE. JRE (Java Runtime Environment) bundles the JVM with core libraries needed to run programs. JVM is the engine that executes bytecode.
| Toolkit | What it contains | Typical command |
|---|---|---|
| JDK | Compiler, debugger, JRE | javac Hello.java |
| JRE | JVM + core libraries | java Hello |
| JVM | Engine that executes bytecode | (none, runs internally) |
5. What is the difference between a class and an object?
Difficulty: Easy
This question appears in nearly every Java Interview Questions for Freshers guide. Keep this answer crisp — it’s a favorite in Java Interview Questions for Freshers screening rounds.
A class is a blueprint for creating objects, while an object is a concrete instance of that class holding real values.
class Car { String model; }
Car tesla = new Car(); // object
6. What is object-oriented programming?
Difficulty: Easy
This is a frequently asked question in Java Interview Questions for Freshers rounds. Many candidates lose marks here, so revise this before any Java Interview Questions for Freshers round.
Object-oriented programming (OOP) organizes code around objects that carry state and behavior, built on four pillars: encapsulation, inheritance, polymorphism, and abstraction.
class Animal {
void makeSound() { System.out.println("..."); }
}
7. What is inheritance?
Difficulty: Easy
Recruiters commonly include this in Java Interview Questions for Freshers checklists. Keep this answer crisp as it’s a favorite in Java Interview Questions for Freshers screening rounds.
Inheritance lets one class (subclass) reuse fields and methods from another class (superclass) using extends.
class Animal { void sound(){} }
class Dog extends Animal { void sound(){ System.out.println("Bark"); } }
8. What is encapsulation?
Difficulty: Easy
This is a staple entry in most Java Interview Questions for Freshers lists. Many candidates lose marks here, so revise this before any Java Interview Questions for Freshers round.
Encapsulation bundles data and methods into a single class and hides internal state behind private fields, exposing controlled access through public methods.
class Account {
private double balance;
public double getBalance(){ return balance; }
}
9. What is polymorphism?
Difficulty: Easy
This question appears in nearly every Java Interview Questions for Freshers guide. Interviewers often circle back to this point in Java Interview Questions for Freshers follow-ups.
Polymorphism allows a single method name to behave differently depending on the object or arguments, achieved through overloading (compile time) or overriding (runtime).
void log(int x){}
void log(String s){}
10. What are access modifiers?
Difficulty: Easy
This comes up often across Java Interview Questions for Freshers interviews. Many candidates lose marks here, so revise this before any Java Interview Questions for Freshers round.
Access modifiers control visibility of a class, method, or variable: public, private, protected, and default (package-private).
public class Demo {
private int secret;
protected int shared;
}
11. What are static variables and methods?
Difficulty: Easy
Recruiters commonly include this in Java Interview Questions for Freshers checklists. Interviewers often circle back to this point in Java Interview Questions for Freshers follow-ups.
Static members belong to the class rather than any instance, so they can be accessed without creating an object.
class Counter {
static int count = 0;
static void increment(){ count++; }
}
12. What are final variables and methods?
Difficulty: Easy
This is a staple entry in most Java Interview Questions for Freshers lists.
A final variable becomes a constant, a final method cannot be overridden, and a final class cannot be extended.
final int MAX = 100;
13. What is a constructor?
Difficulty: Easy
This question appears in nearly every Java Interview Questions for Freshers guide.
A constructor initializes objects, shares its name with the class, and has no return type.
class Point {
int x, y;
Point(){ this(0,0); }
Point(int x, int y){ this.x = x; this.y = y; }
}
14. What is an array?
Difficulty: Easy
This comes up often across Java Interview Questions for Freshers interviews.
An array is a fixed-size collection of elements of the same data type stored in contiguous memory.
int[] nums = {1, 2, 3};
15. What are control structures in Java?
Difficulty: Easy
Recruiters commonly include this in Java Interview Questions for Freshers checklists.
Control structures direct the flow of execution: if-else, switch, loops (for, while, do-while), and break/continue.
for(int i = 0; i < 3; i++) System.out.println(i);
16. What is exception handling?
Difficulty: Easy
This is a staple entry in most Java Interview Questions for Freshers lists.
Exception handling catches and manages runtime errors gracefully using try, catch, finally, and throw, keeping the program from crashing.
try {
int x = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Cannot divide by zero");
}
17. What is the difference between a private and a protected method in Java?
Difficulty: Easy
This comes up often across Java Interview Questions for Freshers interviews.
A private method is accessible only within the same class, while a protected method is accessible within the same class, package, and subclasses.
class Base {
private void secret(){}
protected void shared(){}
}
18. What is the difference between a while loop and a do-while loop in Java?
Difficulty: Easy
This is a staple entry in most Java Interview Questions for Freshers lists.
A while loop checks the condition before executing, while a do-while loop executes the body at least once before checking.
int i = 0;
do { System.out.println(i); i++; } while(i < 3);
19. What is the difference between a static and non-static variable in Java?
Difficulty: Easy
This comes up often across Java Interview Questions for Freshers interviews.
A static variable belongs to the class and is shared by all instances, while a non-static variable belongs to each individual object.
class Demo {
static int shared = 0;
int instanceVal;
}
20. What are text blocks in Java?
Difficulty: Easy
This is a staple entry in most Java Interview Questions for Freshers lists.
Text blocks (Java 15) let you write multi-line strings using triple double-quotes, without escaping every newline or quote.
String json = """
{
"name": "Java"
}
""";
21. What is the difference between == and .equals() in Java?
Difficulty: Easy
This is a frequently asked question in Java Interview Questions for Freshers rounds.
== compares references (memory addresses) for objects, while .equals() compares logical content when overridden, as String does.
String a = new String("hi");
String b = new String("hi");
System.out.println(a == b); // false
System.out.println(a.equals(b)); // true
22. What are default and static methods in interfaces?
Difficulty: Medium
This comes up often across Java Interview Questions for Freshers interviews. Interviewers often circle back to this point in Java Interview Questions for Freshers follow-ups.
From Java 8 onwards, interfaces can contain default methods (with a body, overridable by implementers) and static methods (called directly on the interface).
interface Vehicle {
default void start() { System.out.println("Starting"); }
static Vehicle create() { return new Car(); }
}
23. What is the Optional class and why is it used?
Difficulty: Medium
This is a frequently asked question in Java Interview Questions for Freshers rounds. Keep this answer crisp — it’s a favorite in Java Interview Questions for Freshers screening rounds.
Optional<T>, introduced in Java 8, is a container that may or may not hold a non-null value. It avoids NullPointerException by forcing explicit handling of absent values.
Optional<String> name = Optional.ofNullable(getName());
String result = name.orElse("Guest");
24. What are lambda expressions?
Difficulty: Medium
This is a frequently asked question in Java Interview Questions for Freshers rounds.
A lambda expression is a concise anonymous function, written as (parameters) -> expression, heavily used with functional interfaces and streams.
List<String> names = Arrays.asList("A", "B", "C");
names.forEach(n -> System.out.println(n));
25. What are the different types of exceptions in Java?
Difficulty: Medium
This question appears in nearly every Java Interview Questions for Freshers guide.
Checked exceptions (like IOException) are verified at compile time, while unchecked exceptions (like NullPointerException) surface only at runtime.
throw new IllegalArgumentException("Invalid input");
26. What is the difference between a HashSet and a TreeSet?
Difficulty: Medium
This is a frequently asked question in Java Interview Questions for Freshers rounds.
A HashSet stores unique elements in no particular order using hashing, while a TreeSet keeps unique elements sorted using a red-black tree.
Set<Integer> hs = new HashSet<>(List.of(3,1,2));
Set<Integer> ts = new TreeSet<>(List.of(3,1,2)); // sorted: 1,2,3
27. What is the role of the ClassLoader in Java?
Difficulty: Medium
This comes up often across Java Interview Questions for Freshers interviews.
A ClassLoader loads Java classes into memory at runtime. The three built-in types are Bootstrap, Extension, and Application ClassLoaders, and developers can also write custom loaders.
ClassLoader cl = Demo.class.getClassLoader();
System.out.println(cl);
28. What is the difference between shallow copy and deep copy?
Difficulty: Medium
Recruiters commonly include this in Java Interview Questions for Freshers checklists.
A shallow copy duplicates fields but shares references, so changes in nested objects affect both copies. A deep copy duplicates the object and everything it references.
int[] original = {1,2,3};
int[] deepCopy = original.clone();
29. What is the difference between String, StringBuilder, and StringBuffer in Java?
Difficulty: Medium
This question appears in nearly every Java Interview Questions for Freshers guide.
String is immutable. StringBuilder is mutable and fast but not thread-safe. StringBuffer is mutable and thread-safe due to synchronized methods.
StringBuilder sb = new StringBuilder();
sb.append("Java").append(" Rocks");
30. What is the difference between an abstract class and an interface in Java?
Difficulty: Medium
This comes up often across Java Interview Questions for Freshers interviews.
An abstract class can hold state and partial implementation but cannot be instantiated. An interface defines a contract of methods (with optional default/static bodies) that any class can implement.
abstract class Shape { abstract double area(); }
interface Drawable { void draw(); }
31. How does garbage collection work in Java?
Difficulty: Medium
Recruiters commonly include this in Java Interview Questions for Freshers checklists.
Objects are allocated on the heap. When no live references point to an object, it becomes eligible for garbage collection, and the JVM reclaims that memory automatically.
System.gc(); // requests GC; JVM decides actual timing
32. Provide an example of polymorphism.
Difficulty: Medium
This question appears in nearly every Java Interview Questions for Freshers guide.
A superclass Animal with method makeSound() can be overridden differently by subclasses Dog and Cat, while log() shows overloading.
void log(int x){}
void log(String s){}
@Override
public String toString(){ return "Override example"; }
33. What is a daemon thread?
Difficulty: Medium
This is a frequently asked question in Java Interview Questions for Freshers rounds.
A daemon thread is a low-priority background thread (like the garbage collector) that does not stop the JVM from exiting when all user threads finish.
Thread t = new Thread(() -> System.out.println("bg"));
t.setDaemon(true);
t.start();
34. How do you implement a bubble sort algorithm in Java?
Difficulty: Medium
Recruiters commonly include this in Java Interview Questions for Freshers checklists.
Bubble sort repeatedly swaps adjacent elements that are out of order.
void bubble(int[] a){
for(int i=0;i<a.length-1;i++)
for(int j=0;j<a.length-i-1;j++)
if(a[j]>a[j+1]){ int t=a[j]; a[j]=a[j+1]; a[j+1]=t; }
}
35. How do you implement a binary search algorithm in Java?
Difficulty: Medium
This question appears in nearly every Java Interview Questions for Freshers guide.
Binary search repeatedly halves a sorted array to locate the target element.
int binSearch(int[] a, int key){
int l=0, r=a.length-1;
while(l<=r){
int m=(l+r)/2;
if(a[m]==key) return m;
if(a[m]<key) l=m+1; else r=m-1;
}
return -1;
}
36. What is a thread in Java? Provide an example of how to create a thread.
Difficulty: Medium
This is a frequently asked question in Java Interview Questions for Freshers rounds.
A thread is a lightweight process that runs independently. Threads are created by extending Thread or implementing Runnable.
class MyJob implements Runnable {
public void run(){ System.out.println("Work"); }
}
new Thread(new MyJob()).start();
37. Explain marker interfaces vs functional interfaces.
Difficulty: Medium
This is a staple entry in most Java Interview Questions for Freshers lists.
A marker interface has no methods and simply tags a class for special behavior (Serializable, Cloneable). A functional interface has exactly one abstract method and powers lambda expressions (Runnable, Comparator).
@FunctionalInterface
interface Greet { void say(String name); }
38. What are records in Java, and why were they introduced?
Difficulty: Medium
This is a frequently asked question in Java Interview Questions for Freshers rounds.
A record, introduced in Java 16, is a compact way to create an immutable data-carrier class. The compiler auto-generates the constructor, accessors, equals(), hashCode(), and toString().
record Point(int x, int y) {}
Point p = new Point(3, 4);
System.out.println(p.x());
39. What is pattern matching for switch in Java?
Difficulty: Medium
This comes up often across Java Interview Questions for Freshers interviews.
Pattern matching for switch (standardized in Java 21) lets a switch expression match on types and deconstruct records directly, replacing long instanceof chains.
static String describe(Object obj){
return switch (obj) {
case Integer i -> "int " + i;
case String s -> "string " + s;
default -> "unknown";
};
}
40. What are sealed classes in Java?
Difficulty: Medium
Recruiters commonly include this in Java Interview Questions for Freshers checklists.
Sealed classes (Java 17) restrict which other classes or interfaces may extend or implement them, using the permits keyword, giving more control over class hierarchies.
sealed interface Shape permits Circle, Square {}
final class Circle implements Shape {}
final class Square implements Shape {}
41. What is the difference between Comparable and Comparator in Java?
Difficulty: Medium
This comes up often across Java Interview Questions for Freshers interviews.
Comparable defines a class’s natural ordering via compareTo(), while Comparator defines an external, reusable ordering via compare() without modifying the class.
Collections.sort(list, Comparator.comparing(Student::getMarks));
42. What is the difference between an ArrayList and a LinkedList in Java?
Difficulty: Medium
Recruiters commonly include this in Java Interview Questions for Freshers checklists.
ArrayList stores elements in a resizable array, giving fast random access. LinkedList stores elements as linked nodes, giving fast insertions and deletions at the ends.
List<Integer> arr = new ArrayList<>();
List<Integer> linked = new LinkedList<>();
43. What is method reference in Java, and how is it different from a lambda?
Difficulty: Medium
This is a staple entry in most Java Interview Questions for Freshers lists.
A method reference (::) points to an existing method instead of writing a full lambda body, improving readability when the lambda simply calls one method.
List<String> names = List.of("b", "a", "c");
names.forEach(System.out::println);
44. What is type erasure in Java generics?
Difficulty: Hard
This is a staple entry in most Java Interview Questions for Freshers lists.
Generic type information is removed at compile time and replaced with raw types or bounds, so List<String> and List<Integer> both become List at runtime.
List<String> list = new ArrayList<>();
System.out.println(list.getClass()); // class java.util.ArrayList
45. What is a binary search tree? How can you implement one in Java?
Difficulty: Hard
This is a frequently asked question in Java Interview Questions for Freshers rounds.
A binary search tree stores each node with at most two children, where the left subtree holds smaller values and the right subtree holds larger ones.
class Node {
int val; Node left, right;
Node(int v){ val = v; }
}
Node insert(Node root, int val){
if(root == null) return new Node(val);
if(val < root.val) root.left = insert(root.left, val);
else root.right = insert(root.right, val);
return root;
}
46. How do you implement a merge sort algorithm in Java?
Difficulty: Hard
This is a staple entry in most Java Interview Questions for Freshers lists.
Merge sort recursively splits the array and merges sorted halves back together.
void mergeSort(int[] a, int l, int r){
if(l < r){
int m = (l+r)/2;
mergeSort(a, l, m);
mergeSort(a, m+1, r);
merge(a, l, m, r);
}
}
47. What is a deadlock in Java? How can you prevent it?
Difficulty: Hard
Recruiters commonly include this in Java Interview Questions for Freshers checklists.
A deadlock happens when two or more threads wait on each other’s locks forever. Prevent it by acquiring locks in a consistent order and avoiding nested locks where possible.
synchronized(lockA){
synchronized(lockB){
// always lock A before B everywhere in code
}
}
48. How do you implement a quick sort algorithm in Java?
Difficulty: Hard
This question appears in nearly every Java Interview Questions for Freshers guide.
Quick sort picks a pivot, partitions the array around it, and recursively sorts both halves.
void quick(int[] a, int low, int high){
if(low<high){
int p = partition(a, low, high);
quick(a, low, p-1);
quick(a, p+1, high);
}
}
Interview success comes from understanding concepts, not memorizing answers. If you’re looking to strengthen your Java fundamentals and build real-world applications, explore HCL GUVI’s free Java learning resources and gain hands-on experience with industry-relevant concepts.
The next 10 questions in this Java Interview Questions for Freshers guide cover topics that started showing up regularly in 2025-26 interviews as companies moved onto newer JDK versions.
49. What are virtual threads in Java?
Difficulty: Hard
This question appears in nearly every Java Interview Questions for Freshers guide.
Virtual threads, standardized in Java 21, are lightweight threads managed by the JVM rather than the OS, letting applications run millions of concurrent tasks with far less memory overhead than platform threads.
try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
executor.submit(() -> System.out.println("Running on a virtual thread"));
}
50. What is the difference between fail-fast and fail-safe iterators in Java?
Difficulty: Hard
This question appears in nearly every Java Interview Questions for Freshers guide.
Fail-fast iterators (like ArrayList‘s) throw ConcurrentModificationException if the collection is modified while iterating. Fail-safe iterators (like CopyOnWriteArrayList‘s) operate on a cloned copy and never throw that exception.
List<Integer> list = new CopyOnWriteArrayList<>(List.of(1,2,3));
for (int n : list) list.add(n * 10); // safe, no exception
These 50 Java Interview Questions for Freshers cover the concepts recruiters expect freshers to explain confidently. To build a stronger foundation before your next interview, revise Core Java, OOPs, Collections, Exception Handling, Multithreading, and JVM concepts with HCL GUVI’s free Java Tutorial.
Java OOP Interview Questions for Freshers
Object-oriented programming is where most Java Interview Questions for Freshers actually concentrate, since almost every follow-up question in a technical round branches out from these eight core OOP ideas.
51. What are the four pillars of OOP in Java?
Difficulty: Easy
This is a frequently asked question in Java Interview Questions for Freshers rounds.
The four pillars are encapsulation (hiding data behind methods), inheritance (reusing code across classes), polymorphism (one interface, many behaviors), and abstraction (hiding implementation details behind a simpler interface).
abstract class Payment {
abstract void pay(double amount);
}
52. What is abstraction, and how do you achieve it in Java?
Difficulty: Easy
This comes up often across Java Interview Questions for Freshers interviews.
Abstraction hides implementation details and exposes only what is necessary, achieved in Java through abstract classes and interfaces.
interface Notifier { void send(String msg); }
class EmailNotifier implements Notifier {
public void send(String msg){ System.out.println("Email: " + msg); }
}
53. What is constructor overloading in Java?
Difficulty: Easy
This comes up often across Java Interview Questions for Freshers interviews.
Constructor overloading provides multiple constructors with different parameter lists so objects can be created in different ways.
class Point {
int x, y;
Point(){ this(0,0); }
Point(int x, int y){ this.x = x; this.y = y; }
}
54. What is method overloading, and what rules govern it?
Difficulty: Medium
Recruiters commonly include this in Java Interview Questions for Freshers checklists.
Method overloading allows multiple methods with the same name but different parameter lists (number, type, or order) within the same class, resolved at compile time.
int add(int a, int b){ return a + b; }
double add(double a, double b){ return a + b; }
55. What is method overriding, and what rules govern it?
Difficulty: Medium
This is a staple entry in most Java Interview Questions for Freshers lists.
Method overriding lets a subclass provide its own implementation of a method already defined in its superclass, with the same signature, resolved at runtime.
class Animal { void sound(){ System.out.println("..."); } }
class Dog extends Animal {
@Override
void sound(){ System.out.println("Bark"); }
}
56. Why does Java not support multiple inheritance with classes?
Difficulty: Medium
This question appears in nearly every Java Interview Questions for Freshers guide.
Java avoids multiple inheritance of classes to prevent the “diamond problem,” where two parent classes provide conflicting implementations of the same method. Interfaces (with default methods) provide a safer alternative.
interface A { default void hi(){ System.out.println("A"); } }
interface B { default void hi(){ System.out.println("B"); } }
class C implements A, B {
public void hi(){ A.super.hi(); } // must resolve conflict explicitly
}
57. What is the “is-a” vs “has-a” relationship in OOP?
Difficulty: Medium
This is a frequently asked question in Java Interview Questions for Freshers rounds.
“Is-a” describes inheritance (a Dog is an Animal), while “has-a” describes composition (a Car has an Engine). Composition is often preferred over inheritance for flexibility.
class Engine { void start(){} }
class Car {
private Engine engine = new Engine(); // has-a
}
58. What is the super keyword used for in Java?
Difficulty: Medium
Recruiters commonly include this in Java Interview Questions for Freshers checklists.
super refers to the immediate parent class, used to call the parent constructor, access a hidden parent field, or invoke an overridden parent method.
class Animal { void sound(){ System.out.println("Animal sound"); } }
class Dog extends Animal {
void sound(){ super.sound(); System.out.println("Bark"); }
}
A strong grip on OOP is what separates a confident fresher from a nervous one in a Java Interview Questions for Freshers round. Practice these patterns hands-on with HCL GUVI’s Java Programming course to see each concept run in real code.
Java Collections Interview Questions — Top 10
The Collections Framework is the second most-tested area after OOP in Java Interview Questions for Freshers, since almost every scenario question eventually needs a List, Set, or Map.
59. What is the Collections Framework in Java?
Difficulty: Easy
This is a staple entry in most Java Interview Questions for Freshers lists.
The Collections Framework is a unified architecture of interfaces (List, Set, Map, Queue) and their implementations for storing and manipulating groups of objects.
List<String> list = new ArrayList<>();
Set<String> set = new HashSet<>();
Map<String, Integer> map = new HashMap<>();
60. What is the difference between List, Set, and Map in Java?
Difficulty: Easy
This question appears in nearly every Java Interview Questions for Freshers guide.
A List holds ordered elements that allow duplicates. A Set holds unique elements with no guaranteed order (unless it’s a TreeSet or LinkedHashSet). A Map holds key-value pairs with unique keys.
List<Integer> l = List.of(1,1,2);
Set<Integer> s = Set.of(1,2);
Map<String,Integer> m = Map.of("a",1);
61. How do you iterate over a Map in Java?
Difficulty: Easy
Recruiters commonly include this in Java Interview Questions for Freshers checklists.
The most common approach uses entrySet() with a for-each loop to access both key and value together.
Map<String,Integer> map = Map.of("a",1,"b",2);
for (Map.Entry<String,Integer> e : map.entrySet()) {
System.out.println(e.getKey() + " = " + e.getValue());
}
62. How do you remove duplicates from a List in Java?
Difficulty: Easy
This comes up often across Java Interview Questions for Freshers interviews.
Wrap the list in a Set (which enforces uniqueness) and convert it back if order or list behavior is needed.
List<Integer> nums = new ArrayList<>(List.of(1,2,2,3,3));
List<Integer> unique = new ArrayList<>(new LinkedHashSet<>(nums));
63. What is the difference between HashMap and Hashtable?
Difficulty: Medium
This is a frequently asked question in Java Interview Questions for Freshers rounds.
HashMap allows one null key and multiple null values and is not synchronized. Hashtable is synchronized (thread-safe) but does not allow null keys or values, and is largely considered legacy today.
Map<String,Integer> hm = new HashMap<>();
hm.put(null, 1); // allowed in HashMap
64. What is the difference between HashMap and TreeMap?
Difficulty: Medium
This comes up often across Java Interview Questions for Freshers interviews.
HashMap gives no ordering guarantee and O(1) average lookups. TreeMap keeps keys sorted using a red-black tree, with O(log n) operations.
Map<Integer,String> tm = new TreeMap<>();
tm.put(3,"c"); tm.put(1,"a"); tm.put(2,"b"); // iterates as 1,2,3
65. What is the difference between Iterator and ListIterator in Java?
Difficulty: Medium
This is a staple entry in most Java Interview Questions for Freshers lists.
Iterator traverses any collection forward only, and allows removal. ListIterator works only on List implementations but supports traversing both forward and backward, plus adding and setting elements.
ListIterator<Integer> it = new ArrayList<>(List.of(1,2,3)).listIterator();
while(it.hasNext()) System.out.println(it.next());
66. What is the difference between Comparable and Comparator when sorting a collection?
Difficulty: Medium
This question appears in nearly every Java Interview Questions for Freshers guide.
Comparable is implemented inside the class to define one natural order. Comparator is written externally, letting you sort the same collection in multiple ways without changing the class.
List<Student> students = new ArrayList<>();
students.sort(Comparator.comparing(Student::getName));
67. What are Java Streams, and how do they work with Collections?
Difficulty: Medium
Recruiters commonly include this in Java Interview Questions for Freshers checklists.
Streams (Java 8) let you process collections declaratively using operations like filter(), map(), and collect(), instead of writing manual loops.
List<String> names = List.of("Anu", "Bala", "Chitra");
List<String> longNames = names.stream()
.filter(n -> n.length() > 3)
.collect(Collectors.toList());
Collections questions decide how fast you can write clean, working code in a Java Interview Questions for Freshers round. Strengthen this with hands-on practice through HCL GUVI’s Java Full-stack Developer Course.
68. What is the difference between synchronized collections and concurrent collections?
Difficulty: Hard
This is a frequently asked question in Java Interview Questions for Freshers rounds.
Synchronized collections (like Collections.synchronizedList()) lock the entire collection for every operation. Concurrent collections (like ConcurrentHashMap) use finer-grained locking or lock-free algorithms, giving much better throughput under heavy multithreaded use.
Map<String,Integer> safeMap = new ConcurrentHashMap<>();
safeMap.put("count", 1);
Scenario-Based and Practical Java Interview Questions
69. You are building a login feature. How will you store user passwords securely in Java?
Difficulty: Medium
This is a staple entry in most Java Interview Questions for Freshers lists.
Passwords must never be stored in plain text. Use a hashing algorithm like BCrypt or Argon2 to convert the password into a fixed-length hash, and store only the hash in the database.
import org.mindrot.jbcrypt.BCrypt;
String hashed = BCrypt.hashpw(password, BCrypt.gensalt());
boolean match = BCrypt.checkpw(inputPassword, hashed);
Related Reads: Java Programming Exercises
70. Your program needs to sort millions of records quickly. Which sorting approach will you use?
Difficulty: Medium
This is a frequently asked question in Java Interview Questions for Freshers rounds.
Use Arrays.sort(), which applies Dual-Pivot Quick Sort for primitives and a stable Timsort-based merge sort for objects, both well-optimized for large datasets.
int[] numbers = {5, 3, 1, 4, 2};
Arrays.sort(numbers);
71. You receive a list of email addresses and need to validate them. How will you do it in Java?
Difficulty: Medium
This is a staple entry in most Java Interview Questions for Freshers lists.
Use regular expressions with Pattern and Matcher, compiling the pattern once and reusing it for multiple inputs.
Pattern pattern = Pattern.compile("^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+$");
Matcher matcher = pattern.matcher(email);
if (matcher.matches()) {
System.out.println("Valid email");
}
72. A program must read a very large file line by line without consuming too much memory. What is the solution?
Difficulty: Medium
This question appears in nearly every Java Interview Questions for Freshers guide.
Use BufferedReader, which reads data efficiently and keeps only one line in memory at a time.
try (BufferedReader reader = new BufferedReader(new FileReader("data.txt"))) {
String line;
while ((line = reader.readLine()) != null) {
process(line);
}
}
73. A team reports that your API crashes when it receives null values. How will you handle it?
Difficulty: Medium
This is a frequently asked question in Java Interview Questions for Freshers rounds.
Use the Optional class to represent values that may be absent, replacing direct null checks with isPresent() and orElse().
Optional<String> value = Optional.ofNullable(input);
String result = value.orElse("default");
74. You must share data across different parts of a program, but global variables create conflicts. What will you do?
Difficulty: Medium
This comes up often across Java Interview Questions for Freshers interviews.
Create a Singleton class that holds shared data, with a private constructor and a synchronized getInstance() method.
public class Config {
private static Config instance;
private Config() {}
public static synchronized Config getInstance() {
if (instance == null) instance = new Config();
return instance;
}
}
75. You notice your program creates too many objects and memory usage is high. How will you handle this?
Difficulty: Hard
This question appears in nearly every Java Interview Questions for Freshers guide.
Review the code for classes that can share data through the Flyweight pattern or reuse objects through object pooling. Reuse immutable objects like String where possible, and profile memory using tools like VisualVM to locate leaks.
// Reusing a shared, immutable object instead of creating new ones repeatedly
static final String STATUS_ACTIVE = "ACTIVE";
76. A program must handle multiple users uploading files at the same time. How will you make it thread-safe?
Difficulty: Hard
This comes up often across Java Interview Questions for Freshers interviews.
Use synchronized blocks or locks to prevent two threads writing to the same file simultaneously, choose thread-safe structures like ConcurrentHashMap for shared data, and manage threads through an ExecutorService.
ExecutorService pool = Executors.newFixedThreadPool(10);
pool.submit(() -> uploadFile(userFile));
77. Your REST API must return data quickly, but database queries are slow. How will you improve performance?
Difficulty: Hard
Recruiters commonly include this in Java Interview Questions for Freshers checklists.
Introduce caching for frequently accessed data using libraries like Caffeine, and use connection pooling with HikariCP to speed up database access.
Cache<String, Object> cache = Caffeine.newBuilder()
.expireAfterWrite(10, TimeUnit.MINUTES)
.build();
78. Your system processes payments and must not process the same transaction twice. How will you guarantee this?
Difficulty: Hard
Recruiters commonly include this in Java Interview Questions for Freshers checklists.
Generate a unique transaction ID and store it in a database table with a unique constraint, checking for existence before processing and using optimistic concurrency under high load.
if (transactionRepository.existsById(txnId)) {
throw new DuplicateTransactionException(txnId);
}
Also Read: 100 commonly asked interview questions for Java developer roles
Java Interview Questions Asked at TCS, Infosys, Wipro Campus Drives
TL;DR Summary
- TCS NQT, Infosys, and Wipro Elite/HOLMES campus drives lean heavily on Core Java basics, string handling, and simple logic-building programs rather than advanced frameworks.
- Interviewers at these drives typically ask you to write the code live on a whiteboard or shared editor, so speed and correct syntax matter as much as the concept.
- This section lists the 10 questions freshers most commonly report seeing in TCS, Infosys, and Wipro Java rounds in 2025-26, each with a working answer.
Placement drives from TCS, Infosys, and Wipro are where most engineering freshers in India first face live Java Interview Questions for Freshers, and these companies tend to repeat a fairly predictable pattern year after year.
79. Write a Java program to check if a string is a palindrome.
Difficulty: Easy
This is a staple entry in most Java Interview Questions for Freshers lists.
boolean isPalindrome(String s){
String rev = new StringBuilder(s).reverse().toString();
return s.equals(rev);
}
80. Write a Java program to find the factorial of a number.
Difficulty: Easy
This question appears in nearly every Java Interview Questions for Freshers guide.
long factorial(int n){
return n <= 1 ? 1 : n * factorial(n - 1);
}
81. Write a Java program to check whether a number is prime.
Difficulty: Easy
This is a frequently asked question in Java Interview Questions for Freshers rounds.
boolean isPrime(int n){
if (n < 2) return false;
for (int i = 2; i * i <= n; i++)
if (n % i == 0) return false;
return true;
}
82. Write a Java program to print the Fibonacci series up to n terms.
Difficulty: Easy
This comes up often across Java Interview Questions for Freshers interviews.
void fibonacci(int n){
int a = 0, b = 1;
for (int i = 0; i < n; i++){
System.out.print(a + " ");
int next = a + b; a = b; b = next;
}
}
83. Write a Java program to swap two numbers without using a third variable.
Difficulty: Easy
Recruiters commonly include this in Java Interview Questions for Freshers checklists.
void swap(int a, int b){
a = a + b;
b = a - b;
a = a - b;
System.out.println(a + " " + b);
}
84. Write a Java program to count the number of vowels in a string.
Difficulty: Easy
This is a staple entry in most Java Interview Questions for Freshers lists.
int countVowels(String s){
int count = 0;
for (char c : s.toLowerCase().toCharArray())
if ("aeiou".indexOf(c) != -1) count++;
return count;
}
85. Write a Java program to find the largest element in an array.
Difficulty: Easy
This question appears in nearly every Java Interview Questions for Freshers guide.
int findMax(int[] arr){
int max = arr[0];
for (int n : arr) if (n > max) max = n;
return max;
}
86. Explain the difference between == and equals() for two String objects (a common Wipro follow-up).
Difficulty: Medium
This is a frequently asked question in Java Interview Questions for Freshers rounds.
== checks whether two references point to the same object in memory, while .equals() checks whether the actual content is the same, which matters because of Java’s String pool.
String a = "java";
String b = "java";
System.out.println(a == b); // true, same pool reference
87. Write a Java program to reverse each word in a sentence.
Difficulty: Medium
This comes up often across Java Interview Questions for Freshers interviews.
String reverseWords(String sentence){
String[] words = sentence.split(" ");
StringBuilder result = new StringBuilder();
for (String w : words)
result.append(new StringBuilder(w).reverse()).append(" ");
return result.toString().trim();
}
88. Explain how a HashMap works internally (a common Infosys technical-round question).
Difficulty: Hard
Recruiters commonly include this in Java Interview Questions for Freshers checklists.
A HashMap stores entries in buckets based on the key’s hash code. Collisions within a bucket are resolved with a linked list, which converts to a balanced tree once a bucket grows large enough, keeping lookups close to O(1) on average.
Map<String,Integer> map = new HashMap<>();
map.put("java", 1); // hashCode() decides the bucket index
These 10 questions reflect exactly what recruiters at TCS, Infosys, and Wipro test for in fresher Java Interview Questions for Freshers rounds — simple logic, correct syntax, and a clear explanation of your thought process. Sharpen this with HCL GUVI’s free Java learning resources before your next campus drive.
Common Java Project Questions Asked in Fresher Interviews
This section helps freshers understand how Java projects are evaluated in interviews and what interviewers usually look for when discussing project work. All answers are explained using a simple Student Management System as an example, which freshers can adapt to their own projects.
89. Can you explain your Java project and its purpose?
Difficulty: Easy
This is a staple entry in most Java Interview Questions for Freshers lists.
I worked on a Student Management System developed using Core Java. The purpose of the project is to manage student records such as adding new students, viewing details, updating information, and deleting records, organized using object-oriented principles.
class Student {
int id; String name;
Student(int id, String name){ this.id = id; this.name = name; }
}
90. Which core Java concepts did you apply in your project?
Difficulty: Easy
This question appears in nearly every Java Interview Questions for Freshers guide.
The project uses classes and objects to represent students, encapsulation to protect student data using private variables and public methods, inheritance to reuse common functionality, and polymorphism through method overriding.
class Student {
private String name;
public String getName(){ return name; }
}
91. How did you manage and store data in your project?
Difficulty: Easy
This is a frequently asked question in Java Interview Questions for Freshers rounds.
Student data is stored using an ArrayList, where each student record is added as an object, allowing flexible data management without the size limits of a fixed array.
List<Student> students = new ArrayList<>();
students.add(new Student(1, "Anu"));
92. How is a problem usually approached before writing code in Java?
Difficulty: Easy
This is a staple entry in most Java Interview Questions for Freshers lists.
A clear understanding of the problem is built first by breaking it into smaller parts, identifying input, output, and required logic before writing any code.
// Step 1: identify inputs and outputs before coding the logic
93. Why is breaking a problem into smaller parts important?
Difficulty: Easy
This is a frequently asked question in Java Interview Questions for Freshers rounds. Expect a quick follow-up on this in Java Interview Questions for Freshers interviews.
Breaking a problem into smaller parts makes it easier to solve, reduces mistakes, and makes debugging easier since each part can be tested separately.
void processStudent(Student s){
validate(s);
save(s);
notify(s);
}
94. What matters more while solving a Java problem: syntax or logic?
Difficulty: Easy
This comes up often across Java Interview Questions for Freshers interviews. This pattern is worth memorizing for Java Interview Questions for Freshers rounds.
Logic matters more than syntax. Syntax errors can be fixed quickly with practice or compiler help, but wrong logic produces wrong output regardless of how clean the code looks.
// Correct logic first, then translate it into Java syntax
95. How did you handle errors and invalid input in your project?
Difficulty: Medium
This comes up often across Java Interview Questions for Freshers interviews.
Exception handling is implemented using try-catch blocks to manage runtime errors such as invalid inputs, ensuring the application does not crash on incorrect data.
try {
int id = Integer.parseInt(input);
} catch (NumberFormatException e) {
System.out.println("Invalid student ID");
}
96. How do you explain the execution flow of your Java project?
Difficulty: Medium
Recruiters commonly include this in Java Interview Questions for Freshers checklists.
Execution starts from the main method, displays menu options, accepts input, performs the selected operation, and updates the student data stored in the collection until the user exits.
public static void main(String[] args){
// menu loop calling addStudent(), viewStudent(), etc.
}
97. What is considered first while designing a Java solution?
Difficulty: Medium
This question appears in nearly every Java Interview Questions for Freshers guide. This is exactly the kind of detail Java Interview Questions for Freshers panels probe.
The first step is identifying the main entities and actions involved, then working out relationships between them so the solution can be broken into logical classes and methods.
class Student {}
class Course {}
class Enrollment { Student student; Course course; }
98. How is clarity built when multiple solutions are possible for one problem?
Difficulty: Medium
Recruiters commonly include this in Java Interview Questions for Freshers checklists. This is a core entry in any Java Interview Questions for Freshers checklist.
When multiple solutions exist, each is quickly checked for simplicity and clarity, and the easiest, most understandable approach is chosen first before considering optimizations.
// Choose the simplest working approach, then optimize if needed
Many fresher interviews include questions on Collections Framework, Exception Handling, Threads, and JVM internals. Master these concepts through HCL GUVI’s free Java Tutorial and prepare with confidence for technical interviews.

Java Interview Preparation Roadmap for Freshers
| Preparation Stage | What To Focus On | How To Prepare Effectively |
|---|---|---|
| Java Fundamentals | Syntax, data types, operators, control statements, basic I/O | Practice small programs daily, focus on loops and conditionals |
| Object-Oriented Programming | Classes, objects, inheritance, polymorphism, abstraction, encapsulation | Learn each concept with real-world examples and implement it in code |
| Core Java Concepts | Constructors, access modifiers, static and final keywords, interfaces | Write short programs to see how keywords behave in practice |
| Exception Handling | Try-catch blocks, checked and unchecked exceptions, custom exceptions | Create programs that generate errors and handle them properly |
| Collections Framework | List, Set, Map, ArrayList, HashMap, iteration techniques | Practice choosing the right collection for different data needs |
| Multithreading Basics | Thread creation, thread lifecycle, synchronization basics | Understand concepts first, then write simple multithreaded programs |
| Java 17-21 Features | Records, sealed classes, pattern matching, virtual threads | Rewrite one old program using these newer features to see the difference |
Start your career in full-stack development with HCL GUVI’s Certified Java Full-stack Developer Course (a part of the Zen Class programs) and gain job-ready skills in Java, Spring, HTML, CSS, and JavaScript through live classes and recorded sessions. With expert mentorship, practical training, and placement support from 600+ hiring partners, this program helps you build strong industry-ready skills.
Conclusion
If you are a fresher, focus on learning Java basics first and then work through this full set of Java Interview Questions for Freshers step by step, including the OOP section, Collections top 10, and the TCS, Infosys, and Wipro campus-drive questions. This will help you build confidence, understand concepts clearly, and perform better across every round of your interview. With consistent practice, you can improve your chances of getting your first job in the software industry.
FAQs
Do I need to learn advanced Java concepts as a fresher to clear interviews?
Focus is mainly on strong basics; advanced topics are not the primary expectation at the fresher level.
How much coding practice is enough for Java interview preparation?
Regular practice of basic programs and common interview questions helps build confidence and clarity.
Are scenario-based questions really asked in fresher interviews?
Simple real-world scenarios are often used to test thinking and problem-solving approach.
What if I forget answers during the interview?
Explaining what you know and thinking step by step creates a better impression than staying silent.
Is project knowledge important even for freshers?
Project discussions help interviewers understand how concepts are applied in real situations.
How should I prepare from this blog effectively?
Start with basics, understand concepts clearly, practice questions, and then move to scenarios and projects step by step.



Very helpful information 😊💥
This website is incredibly helpful for Java beginners! The interview questions are well-structured, easy to understand, and cover all the important concepts clearly. It's a great resource for freshers preparing for Java interviews. Thank you for creating such valuable content — keep up the great work!
very nice and it's useful for the freshers.
very nice topic for freshers.
The content had a lot of information and it is in very simple and understandable format for students. Thank you for this sirr.
nice questiones =]sd
It's really helpful
Excellent
Its really helpful.
excellent
excellent
It was intresting
Excellent questions
its useful, nice.
we are includes more questions .it's include more useful
this content is very important to me. can you make on SQL
Nice