Top 100 Java Fresher Interview Questions and Answers (Updated for Java 21 in 2025) - Certification Guide
Core Java Basics
1. What is Java?
Java is a high-level, object-oriented programming language that runs on the JVM. It follows the “write once, run anywhere” principle.
2. Why is Java platform independent?
Because the compiler produces bytecode that runs on any system with a JVM, regardless of OS.
3. What is JVM?
The Java Virtual Machine executes bytecode, translates it into machine code, and provides runtime services like garbage collection.
4. What is the difference between JDK, JRE, and JVM?
-
JDK: Development tools + JRE.
-
JRE: JVM + libraries.
-
JVM: Executes bytecode.
5. What is the difference between a class and an object?
A class is a blueprint, while an object is an instance of that blueprint.
6. What is object-oriented programming?
OOP organizes code around objects and emphasizes encapsulation, inheritance, polymorphism, and abstraction.
7. What are default and static methods in interfaces?
Default methods have a body and can be overridden. Static methods belong to the interface itself.
8. What is inheritance?
A mechanism where a class (child) inherits properties and methods from another class (parent).
9. What is encapsulation?
The bundling of data and methods in a class, with controlled access using access modifiers.
10. What is polymorphism?
The ability for one method or interface to have multiple implementations (overloading and overriding).
Java Essentials
11. What is the Optional class and why is it used?
It’s a container for values that may be null, helping avoid NullPointerException.
12. What are access modifiers?
Keywords (public, private, protected, default) that control visibility of classes, methods, and variables.
13. What are static variables and methods?
They belong to the class rather than instances and can be accessed without objects.
14. What are final variables, methods, and classes?
Final variable = constant, method = cannot override, class = cannot extend.
15. What is a constructor?
A special method that initializes objects when created.
16. What are lambda expressions?
A short syntax for anonymous functions, used with functional interfaces and streams.
17. What is an array?
A fixed-size collection of elements of the same type, accessed by index.
18. What are control structures in Java?
They manage program flow: if-else, switch, loops, break, continue.
19. What is exception handling?
A mechanism using try-catch-finally to handle runtime errors gracefully.
20. What are the different types of exceptions in Java?
Checked (compile-time) and unchecked (runtime) exceptions.
Collections & Generics
21. What is the difference between a HashSet and a TreeSet?
HashSet is unordered; TreeSet is sorted. Both store unique elements.
22. What is the difference between ArrayList and LinkedList?
ArrayList is faster for random access, LinkedList is better for frequent insertions/deletions.
23. What is the difference between shallow copy and deep copy?
Shallow copy copies references; deep copy copies actual data.
24. What is type erasure in Java generics?
Generics information is removed at compile-time for backward compatibility.
25. What is the difference between String, StringBuilder, and StringBuffer?
String = immutable, StringBuilder = mutable (faster), StringBuffer = mutable (thread-safe).
26. What is the Map interface in Java?
It stores key-value pairs, with unique keys. Example: HashMap.
27. What is a ConcurrentHashMap?
A thread-safe map with better concurrency than Hashtable.
28. How does HashMap handle collisions?
Using chaining (linked lists or trees from Java 8 onwards).
29. What is the difference between HashMap and TreeMap?
HashMap is unordered; TreeMap keeps sorted keys.
30. What is the difference between fail-fast and fail-safe iterators?
Fail-fast throws ConcurrentModificationException; fail-safe works on a copy.
OOP & Advanced OOP
31. What is a daemon thread?
A background thread that supports other threads, e.g., GC.
32. What is the difference between a private and a protected method?
Private = same class only, Protected = same package + subclasses.
33. What is the difference between an abstract class and an interface?
Abstract class can have fields and constructors; interface is a contract of methods.
34. What is multiple inheritance in Java? Can it be achieved?
Classes cannot extend multiple classes, but can implement multiple interfaces.
35. What are sealed classes and interfaces in Java 21?
They restrict which classes can extend/implement them.
36. What are record classes in Java?
Immutable data carriers with auto-generated constructors, equals, hashCode, toString.
37. What is pattern matching for instanceof?
Allows type casting directly in instanceof checks.
38. What is the difference between equals() and == in Java?
equals() checks content; == checks references.
39. What is method overloading vs method overriding?
Overloading = same method name, different parameters; Overriding = same method signature in subclass.
40. What are marker vs functional interfaces?
Marker = no methods (e.g., Serializable). Functional = one abstract method (e.g., Runnable).
Multithreading & Concurrency
41. What is a thread in Java? Provide an example.
A lightweight process of execution; created via Thread or Runnable.
42. What is synchronization in Java?
A mechanism to control thread access to shared resources.
43. What is a volatile keyword?
Ensures a variable is read from main memory, not cache.
44. What is a deadlock? How can you prevent it?
When two threads wait on each other forever; avoid nested locks or use timeouts.
45. What is a race condition?
When multiple threads access shared data unsafely.
46. What is the difference between Runnable and Callable?
Runnable returns void; Callable returns a value and can throw exceptions.
47. What is the Executor framework?
A framework to manage thread pools instead of manually creating threads.
48. What is the ForkJoinPool?
A thread pool designed for recursive divide-and-conquer tasks.
49. What are virtual threads in Java 21 (Project Loom)?
Lightweight threads managed by JVM, allowing millions of concurrent tasks.
50. What is structured concurrency in Java 21?
A new API to manage related tasks as a single unit, simplifying cancellation and error handling.
Algorithms in Java
51. How do you implement bubble sort in Java?
Repeatedly swap adjacent elements until sorted.
52. How do you implement binary search in Java?
Divide the array in half until the element is found or not.
53. How do you implement merge sort in Java?
Recursively split array, then merge sorted halves.
54. How do you implement quick sort in Java?
Partition array around a pivot, then sort partitions recursively.
55. How do you reverse a string in Java?
Use StringBuilder’s reverse() or iterate manually.
56. How do you find the largest element in an array?
Iterate and track the max value.
57. How do you check if a string is a palindrome?
Compare characters from both ends.
58. How do you remove duplicates from an array?
Use a HashSet or Stream distinct().
59. How do you count word frequency in a string?
Use a Map with words as keys and counts as values.
60. How do you find the second largest element in an array?
Track max and second max during iteration.
Java Memory & Performance
61. What is garbage collection in Java?
Automatic memory management that reclaims unused objects.
62. How does the JVM manage memory?
Divides memory into heap, stack, metaspace, and uses GC.
63. What are strong, weak, soft, and phantom references?
Types of references affecting GC eligibility.
64. What is the difference between stack and heap memory?
Stack = method calls/variables, Heap = objects.
65. What is the finalize() method?
A method called before GC, but discouraged in modern Java.
66. What is memory leak in Java?
Unreferenced objects remain in memory due to lingering references.
67. What is the difference between serial and parallel garbage collectors?
Serial uses one thread, parallel uses multiple threads.
68. What is the G1 garbage collector?
A low-latency, region-based GC suitable for large heaps.
69. What is ZGC (Z Garbage Collector)?
A scalable, low-pause GC for very large heaps.
70. How do you monitor JVM performance?
Using tools like JVisualVM, JConsole, or Flight Recorder.
Java 17–21 Modern Features
71. What is a text block in Java?
A multiline string enclosed in """
, introduced in Java 15.
72. What is the difference between switch expressions and traditional switch?
Switch expressions return values and use arrow syntax.
73. What is pattern matching for switch (Java 21)?
Allows type checks and extraction directly in switch cases.
74. What is the difference between sealed classes and enums?
Enums define fixed constants; sealed classes define fixed inheritance hierarchy.
75. What is foreign function & memory API in Java 21 (Project Panama)?
Allows safe, efficient interaction with native code and memory.
76. What is vector API in Java?
Provides SIMD operations for better performance.
77. What are improvements in records in Java 21?
Records now support pattern matching and better inheritance.
78. What is a scoped value in Java 21?
A lightweight alternative to ThreadLocal for sharing immutable data.
79. What is string templates (preview in Java 21)?
New syntax for embedding expressions directly into strings.
80. What is the purpose of preview features in Java?
To let developers test new features before they become permanent.
Java I/O & Streams
81. What is the difference between byte streams and character streams?
Byte streams handle raw data; character streams handle text with encoding.
82. What is the difference between FileReader and BufferedReader?
FileReader reads characters; BufferedReader adds buffering and readLine().
83. What is serialization in Java?
Converting objects into a byte stream for storage or transfer.
84. What is the transient keyword?
Marks fields to be skipped during serialization.
85. What is the difference between InputStream and OutputStream?
InputStream reads bytes, OutputStream writes bytes.
86. What is NIO in Java?
New I/O API with channels, buffers, and non-blocking I/O.
87. What is the difference between Files.readString() and Scanner?
Files.readString() reads whole file; Scanner reads token by token.
88. How do you list files in a directory using Java?
Using File.listFiles() or NIO Files.walk().
89. What is the difference between PrintWriter and BufferedWriter?
PrintWriter is for formatted text, BufferedWriter adds efficiency with buffering.
90. What is object serialization in Java 21’s foreign memory API?
It allows structured mapping of Java objects to native memory.
JDBC & Database
91. What is JDBC?
Java API for connecting and executing SQL queries on databases.
92. What is the difference between Statement, PreparedStatement, and CallableStatement?
Statement = static SQL, PreparedStatement = precompiled with parameters, CallableStatement = calls stored procedures.
93. What are batch updates in JDBC?
Executing multiple SQL statements as a batch for efficiency.
94. What is connection pooling?
Reusing database connections instead of creating new ones each time.
95. What is the difference between ResultSet.next() and ResultSet.absolute()?
next() moves forward one row; absolute() jumps to a specific row.
96. What is SQL Injection? How to prevent it in Java?
Malicious SQL input; prevented using PreparedStatement.
97. How do you connect Java to a database?
Load driver, get connection via DriverManager, execute queries.
98. What are JDBC drivers?
Software components that allow Java to interact with databases.
99. What is the role of DriverManager class?
Manages JDBC drivers and establishes connections.
100. What are improvements to JDBC in modern Java versions?
Better integration with streams, try-with-resources, and newer SQL types.
Importance of Java Certification for Freshers
For a fresher, getting certified in Java is more than just adding a line to the résumé — it’s proof of both theoretical knowledge and practical coding ability. Recruiters often use certifications to shortlist candidates when hundreds of applications arrive for the same entry-level role.
Here’s why certifications matter for a fresher in 2025:
-
Validation of Skills – Proves you understand Java fundamentals, OOP, and modern Java (Java 11–21).
-
Competitive Edge – Sets you apart from non-certified candidates.
-
Career Entry Point – Helps land internships and junior developer roles.
-
Structured Learning – Certification preparation ensures you follow a proper roadmap.
-
Future Readiness – Certifications are updated with the latest Java versions (e.g., Java 21), aligning your skills with industry demand.
Java Certification Path for Freshers
Here’s the official Oracle Java Certification Path with relevant practice links from MyExamCloud:
-
Oracle Java Foundations (1Z0-811)
Best for absolute beginners; covers Java basics, OOP, and simple programming.
Java Foundations Practice Tests -
Oracle Certified Associate, Java SE 8 Programmer (1Z0-808)
Entry-level certification to validate core Java SE 8 concepts.
OCAJP 8 Practice Tests -
Oracle Certified Professional, Java SE 8 Programmer (1Z0-809)
Next step after OCA; deepens understanding of Java SE 8 features.
OCPJP 8 Practice Tests -
Oracle Certified Professional: Java SE 11 Developer (1Z0-819)
Industry-standard certification for Java SE 11 developers.
Java SE 11 Developer Practice Tests -
Oracle Certified Professional: Java SE 17 Developer (1Z0-829)
Focuses on Java SE 17 features such as sealed classes and records.
Java SE 17 Developer Practice Tests -
Oracle Certified Professional: Java SE 21 Developer (1Z0-830)
Latest certification aligned with Java 21, including virtual threads, structured concurrency, and string templates.
Java SE 21 Developer Practice Tests -
Oracle Certified Professional, Java EE 7 Application Developer (1Z0-900)
For those who want to specialize in enterprise Java applications.
Java EE 7 Developer Practice Tests
Suggested Path for Freshers in 2025
-
Start with Java Foundations (1Z0-811) if you’re new.
-
Move to Java SE 11/17 certifications (1Z0-819 or 1Z0-829).
-
Aim for Java SE 21 (1Z0-830) to showcase the latest skills.
-
Optionally, branch into Java EE 7 (1Z0-900) if you’re targeting enterprise development.
Author | JEE Ganesh | |
Published | 3 weeks ago | |
Category: | Java Certification | |
HashTags | #Java #Programming #Software #JavaCertification |