🟢 30 Basic Java Interview Questions for Freshers (with Examples & Use Cases)
If you are preparing for interviews in service-based companies like TCS, Infosys, Accenture, Wipro, Tech Mahindra, these are the most commonly asked Java interview questions for freshers (<1 year experience).
Each question has:
✅ Simple explanation
✅ Real-life use case
✅ Small code example
1. What are the main features of Java?
Answer:
-
Object-Oriented
-
Platform Independent
-
Simple, Secure, Robust
-
Multithreaded & Portable
👉 Use Case: Run same .class
file on Windows & Linux.
2. What is JVM, JRE, and JDK?
Answer:
-
JVM: Runs Java bytecode.
-
JRE: Libraries + JVM.
-
JDK: JRE + tools (javac, debugger).
3. Why is Java platform independent?
Because Java code is compiled into bytecode, which runs on any JVM.
4. Difference between ==
and equals()
?
-
==
→ compares memory reference. -
equals()
→ compares values.
5. Difference between Primitive and Wrapper?
-
Primitive →
int
,char
(not objects). -
Wrapper →
Integer
,Character
(objects with utilities).
6. What are Constructors?
Special method used to initialize objects.
7. Difference between Overloading and Overriding?
-
Overloading: Same method, different parameters.
-
Overriding: Subclass changes parent method.
8. What is Inheritance?
One class acquires properties of another.
9. What is Polymorphism?
One method behaves differently depending on context.
10. What is Abstraction?
Hiding implementation, showing only behavior.
11. What is Encapsulation?
Binding variables & methods, restricting direct access.
12. Difference between Abstract Class & Interface?
-
Abstract: Can have abstract + concrete methods.
-
Interface: Only abstract (till Java 7), can have default/static (Java 8+).
13. What are Access Modifiers?
-
public
,private
,protected
,default
.
14. Difference between final, finally, finalize()?
-
final: Constant/prevent inheritance.
-
finally: Executes after try-catch.
-
finalize(): Cleanup before GC.
15. Difference between String, StringBuffer, StringBuilder?
-
String → Immutable.
-
StringBuffer → Mutable + thread-safe.
-
StringBuilder → Mutable + fast.
16. What are Static Variables & Methods?
Shared by all objects, belongs to class.
17. Use of this
keyword?
Refers to current object.
18. Checked vs Unchecked Exceptions?
-
Checked: Must be handled (IOException).
-
Unchecked: Runtime (NullPointerException).
19. What is Garbage Collection?
Automatic memory management.
20. What are Threads?
Lightweight processes for multitasking.
21. What is Synchronization?
Ensures one thread at a time.
22. Difference between Array & ArrayList?
-
Array: Fixed size.
-
ArrayList: Dynamic.
23. Difference between HashMap & Hashtable?
-
HashMap → Not synchronized, allows null.
-
Hashtable → Synchronized, no null keys.
24. Difference between Iterator & ListIterator?
-
Iterator → one direction.
-
ListIterator → both directions.
25. Difference between throw & throws?
-
throw
→ used to throw exception. -
throws
→ declares exceptions in method.
26. Compile-time vs Runtime Polymorphism?
-
Compile-time: Overloading.
-
Runtime: Overriding.
27. What are Packages?
Collection of related classes.
28. Why public static void main(String[] args)
?
-
public
: accessible -
static
: no object needed -
void
: no return -
main
: entry point
29. Heap vs Stack Memory?
-
Stack: stores method calls & local vars.
-
Heap: stores objects.
30. Process vs Thread?
-
Process: Independent, own memory.
-
Thread: Part of process, shared memory.
Comments
Post a Comment