Java is still one of the most asked languages in fresher technical interviews at TCS, Infosys, Wipro, Accenture, Cognizant and Capgemini. The good news: interviewers keep coming back to the same core concepts. If you can explain these 25 questions in your own words and write the small code snippets from memory, you will handle most Java rounds with confidence.
Key takeaways
- Most fresher Java interviews focus on OOP, strings, collections, exceptions and basic Java 8 features.
- Interviewers care more about clear explanations and simple examples than memorised definitions.
- Questions like "== vs equals()", "String vs StringBuilder" and "HashMap working" appear in almost every service-company interview.
- Pair Java theory with daily DSA practice, because most companies also run a coding round.
Java basics
1. What are JDK, JRE and JVM?
The JVM (Java Virtual Machine) runs compiled bytecode. The JRE is the JVM plus the standard libraries needed to run programs. The JDK is the JRE plus development tools like the compiler (javac). To write and compile Java you need the JDK; to only run it, the JRE is enough.
2. Why is Java called platform independent?
Java code is compiled into bytecode, not machine code. Any system with a JVM can run that bytecode, so the same .class file works on Windows, Linux or macOS. This is the "write once, run anywhere" idea.
3. What are the primitive data types in Java?
There are eight: byte, short, int, long, float, double, char and boolean. Everything else (String, arrays, objects) is a reference type.
4. Explain public static void main(String[] args).
public lets the JVM call it from outside the class, static means no object is needed to call it, void means it returns nothing, and String[] args holds command-line arguments.
5. What is the difference between == and equals()?
== compares references (do both variables point to the same object?). equals() compares content, if the class overrides it, as String does.
String a = new String("java");
String b = new String("java");
System.out.println(a == b); // false
System.out.println(a.equals(b)); // true
OOP concepts
6. What are the four pillars of OOP?
Encapsulation (hiding data behind methods), Inheritance (reusing a parent class), Polymorphism (one name, many forms) and Abstraction (showing only what is needed). Give a real example for each โ interviewers love that.
7. What is the difference between method overloading and overriding?
Overloading: same method name, different parameters, in the same class โ decided at compile time. Overriding: a child class gives its own version of a parent method with the same signature โ decided at runtime.
class Shape { double area() { return 0; } }
class Circle extends Shape {
double r = 2;
@Override
double area() { return Math.PI * r * r; }
}
8. Abstract class vs interface?
An abstract class can have state (fields), constructors and both abstract and normal methods; a class can extend only one. An interface defines a contract; since Java 8 it can have default and static methods, and a class can implement many interfaces.
9. Why does Java not support multiple inheritance with classes?
To avoid the "diamond problem", where two parent classes have the same method and the child does not know which one to use. Java allows multiple inheritance of type through interfaces instead.
10. What is a constructor? Can it be private?
A constructor initialises a new object and has the same name as the class with no return type. Yes, it can be private โ this is used in the Singleton pattern so that outside code cannot create objects.
11. What do this and super mean?
this refers to the current object; super refers to the parent class, and is used to call the parent constructor or a parent method.
12. What does the final keyword do?
A final variable cannot be reassigned, a final method cannot be overridden, and a final class cannot be extended (String is a final class).
Strings
13. Why is String immutable in Java?
Once created, a String object cannot change. This makes Strings safe to share in the String pool, safe to use as HashMap keys, and thread-safe.
14. String vs StringBuilder vs StringBuffer?
String is immutable. StringBuilder is mutable and fast, but not synchronized. StringBuffer is mutable and synchronized (thread-safe) but slower. Use StringBuilder when building strings in a loop.
StringBuilder sb = new StringBuilder("code");
sb.append("mbs").reverse();
System.out.println(sb); // sbmedoc
15. Write a program to check whether a string is a palindrome.
A favourite coding warm-up. Compare characters from both ends.
static boolean isPalindrome(String s) {
int i = 0, j = s.length() - 1;
while (i < j) {
if (s.charAt(i++) != s.charAt(j--)) return false;
}
return true;
}
Collections
16. ArrayList vs LinkedList?
ArrayList uses a dynamic array โ fast random access by index, slower inserts in the middle. LinkedList uses a doubly linked list โ faster inserts and deletes at known positions, slower access by index.
17. How does HashMap work internally?
HashMap stores key-value pairs in an array of buckets. It calls hashCode() on the key to pick a bucket and uses equals() to find the exact key inside it. Since Java 8, a bucket with many collisions is converted into a balanced tree for faster lookup.
18. HashMap vs Hashtable?
HashMap is not synchronized and allows one null key; Hashtable is synchronized and allows no null keys or values. For thread-safe maps in modern code, use ConcurrentHashMap.
19. List vs Set vs Map?
A List keeps order and allows duplicates. A Set does not allow duplicates. A Map stores key-value pairs with unique keys.
20. Write code to count the frequency of each character in a string.
This tests HashMap usage.
Map<Character, Integer> freq = new HashMap<>();
for (char c : "banana".toCharArray()) {
freq.put(c, freq.getOrDefault(c, 0) + 1);
}
System.out.println(freq); // {a=3, b=1, n=2}
Exceptions, threads and Java 8
21. Checked vs unchecked exceptions?
Checked exceptions (like IOException) must be handled or declared at compile time. Unchecked exceptions (like NullPointerException, ArithmeticException) extend RuntimeException and are not checked by the compiler.
22. What is the difference between final, finally and finalize?
final is a keyword for constants and restrictions, finally is a block that runs after try/catch (used to close resources), and finalize() was an old cleanup method called by the garbage collector โ it is deprecated, so mention try-with-resources instead.
23. How do you create a thread in Java?
Either extend the Thread class or implement Runnable (preferred, since your class can still extend another class). Call start(), not run(), to begin a new thread.
Runnable task = () -> System.out.println("Running in " + Thread.currentThread().getName());
new Thread(task).start();
24. What is a lambda expression?
A short way to write an implementation of a functional interface (an interface with one abstract method), introduced in Java 8. It makes code for sorting, filtering and event handling much shorter.
25. What is the Stream API? Give an example.
Streams let you process collections in a declarative way using operations like filter, map and collect.
List<Integer> nums = List.of(1, 2, 3, 4, 5, 6);
List<Integer> evenSquares = nums.stream()
.filter(n -> n % 2 == 0)
.map(n -> n * n)
.collect(Collectors.toList());
System.out.println(evenSquares); // [4, 16, 36]
How to prepare for a Java interview in 2 weeks
- Days 1โ4: Revise basics, OOP and strings. Write every snippet above by hand without an IDE.
- Days 5โ8: Collections and exceptions. Solve 10 easy array and string problems using ArrayList and HashMap.
- Days 9โ11: Java 8 lambdas and streams, plus basic multithreading.
- Days 12โ14: Mock interviews. Explain each concept aloud in under a minute, and practise one company-specific test pattern.
For a structured path, our Java programming course covers all of these topics with practice problems, and the Data Structures & Algorithms course prepares you for the coding round. If you are targeting a mass recruiter, also check the TCS NQT preparation page and our full placement preparation hub. To go deeper into official concepts, the dev.java learning path and Oracle's Java tutorials are reliable free references.
Related guides
- 25 Python Interview Questions for Freshers (2026) + Answers
- SQL Interview Questions for Freshers 2026 + Answers
- Tier-3 College Placement Roadmap 2026: 6-Month IT Job Plan
- Cognizant GenC 2027: Eligibility, Process & Prep Plan
- DSA Roadmap for Placements
FAQ
Is Java still good for freshers in 2026?
Yes. Java remains widely used in enterprise software, banking systems and Android, and most IT service companies accept Java for coding rounds and technical interviews.
Which Java topics are most important for fresher interviews?
OOP concepts, String vs StringBuilder, == vs equals(), collections (especially HashMap and ArrayList), exception handling and basic Java 8 features like lambdas and streams.
Should I learn Java or Python for placements?
Either works for coding rounds. Java is a strong choice for service companies and backend roles; Python is popular for data and AI roles. Pick one for DSA and master it rather than switching.
How many coding problems should I practise before a Java interview?
Aim for at least 60โ100 easy and medium problems on arrays, strings, hashing and recursion, written in Java, so that syntax never slows you down.
Conclusion
Java interviews for freshers reward clarity. Learn these 25 questions, practise the code until you can write it without help, and explain each answer with a small real-world example. Combine that with daily DSA practice and mock tests, and you will walk into your technical round ready. Want mentor-led practice and mock interviews? Explore CodeMBS membership.
๐ข Get verified job alerts every day โ free
Fresher drives, internships and IT jobs with official apply links only. No fake links, no fees.
More articles

Coursera Global Skills Report 2026: India Ranks 40th on AI-Human Skills โ What Students Should Learn Next
Coursera Global Skills Report 2026 ranks India 40th on AI-human skills. What the data means for students and which skills to build next.
Read article โ
Naukri JobSpeak Nov 2026: AI/ML Jobs Up 20%, IT Services Down 5% โ What Freshers Should Do Now
Naukri JobSpeak Nov 2026: AI/ML hiring rose 20% and BFSI fresher hiring 21% while IT services fell 5%. What it means for freshers and what โฆ
Read article โ