Most Asked Java Interview Questions, Set 1
Core Java interview questions for freshers: JDK vs JRE, == vs .equals(), overloading vs overriding, abstract class vs interface, exception handling, and collections.
Java’s core interview questions look almost the same whether you’re applying to a service company or a product startup. Knowing eight answers thoroughly matters more than skimming twenty.
Most fresher placement technical rounds cover the same set of topics: the Java execution stack, reference equality, access control, OOP design, error handling, and the Collections framework. This article covers ten of the most consistently asked questions, in the order interviewers tend to reach for them.
Java Environment: JDK, JRE, and JVM
1. What is the difference between JDK, JRE, and JVM?
These three acronyms describe three layers of the Java execution stack. Interviewers ask this in almost every first technical round because the answer reveals whether a candidate understands how Java actually runs.
| Component | What It Contains | When You Need It |
|---|---|---|
| JVM (Java Virtual Machine) | Bytecode interpreter; converts .class files to machine code | Always: every Java program runs inside a JVM |
| JRE (Java Runtime Environment) | JVM + standard class libraries | When running Java apps without writing code |
| JDK (Java Development Kit) | JRE + compiler (javac) + debugger + tools | When writing and compiling Java programs |
The hierarchy is: JDK contains JRE, which contains JVM. The Oracle Java SE 21 documentation covers the full standard library that ships with the JDK.
Core Language Concepts
2. What is the difference between == and .equals() in Java?
The distinction is between reference equality and content equality.
==compares memory addresses. It returnstrueonly when both variables point to the exact same object in memory..equals()compares the contents of two objects. The defaultObject.equals()behaves like==, butString,List, and most value-holding classes override it to compare values instead.
String s1 = new String("FACE");
String s2 = new String("FACE");
System.out.println(s1 == s2); // false (different objects in memory)
System.out.println(s1.equals(s2)); // true (same content)
The practical rule: use .equals() for String comparisons in application code. Using == on Strings is one of the most common fresher Java bugs, and it can silently produce wrong results when the JVM string pool returns a cached object.
3. What are Java access modifiers?
Access modifiers control visibility of classes, methods, and variables. Java has four.
| Modifier | Same Class | Same Package | Subclass | Outside Package |
|---|---|---|---|---|
private | Yes | No | No | No |
default (no keyword) | Yes | Yes | No | No |
protected | Yes | Yes | Yes | No |
public | Yes | Yes | Yes | Yes |
A member declared without a modifier gets default access. Use protected when you need a field accessible in subclasses but not in unrelated classes outside the package.
4. What is the difference between static and final in Java?
staticmakes a member belong to the class rather than to any specific instance. All objects of the class share astaticvariable. Astaticmethod can be called without creating an object first.finalprevents change. Afinalvariable is a constant; afinalmethod cannot be overridden; afinalclass cannot be subclassed.
Both keywords can appear together: public static final int MAX = 100; is a class-level constant, the standard way to define a compile-time constant in Java.
Object-Oriented Design
5. What is the difference between method overloading and method overriding?
Both involve methods with the same name, but they operate across different class relationships.
| Feature | Overloading | Overriding |
|---|---|---|
| Class relationship | Same class | Parent and child class |
| Parameters | Must differ (type, count, or order) | Must be identical |
| Return type | Can differ | Must match (or be covariant) |
| Resolution time | Compile time (static dispatch) | Runtime (dynamic dispatch) |
static methods | Can be overloaded | Cannot be overridden |
Overloading is about convenience: one method name, multiple signatures for different input types. Overriding is about polymorphism: a child class redefines a parent’s behavior for runtime flexibility.
6. What is the difference between an abstract class and an interface?
This is the most nuanced OOP question at the fresher level. Java 8 changed the answer by allowing default and static methods in interfaces.
| Feature | Abstract Class | Interface |
|---|---|---|
| Concrete methods | Allowed | Only as default or static (Java 8+) |
| Instance variables | Allowed | Only public static final constants |
| Constructor | Allowed | Not allowed |
| Multiple inheritance | Not supported | Supported |
| Method access | Any modifier | public by default |
The design rule: use an abstract class when you want shared state or partial implementation; use an interface when you want a contract that unrelated classes can implement independently. The 20 most-asked data structures interview questions covers related polymorphism questions that come up alongside OOP design in technical rounds.
Exception Handling and Collections
7. What are the two types of exceptions in Java?
Java exceptions divide into two categories based on when the compiler notices them.
- Checked exceptions (compile-time): the compiler forces you to handle or declare them with
throws. Examples:IOException,SQLException,ClassNotFoundException. - Unchecked exceptions (runtime): subclasses of
RuntimeException. The compiler does not require explicit handling. Examples:NullPointerException,ArrayIndexOutOfBoundsException,ClassCastException.
Both types are handled with try-catch-finally. The finally block runs regardless of whether an exception occurred or was caught (useful for resource cleanup).
8. What is the Java Collections Framework?
The Java Collections Framework (JCF) provides ready-to-use data structures for storing and processing groups of objects. OpenJDK maintains the open-source reference implementation that most JDKs ship.
| Interface | Description | Common Implementations |
|---|---|---|
List<E> | Ordered, allows duplicates | ArrayList, LinkedList |
Set<E> | Unique elements only | HashSet, TreeSet, LinkedHashSet |
Queue<E> | FIFO ordering | PriorityQueue, ArrayDeque |
Map<K,V> | Key-value pairs | HashMap, TreeMap, LinkedHashMap |
For working code in Java and other languages, the Java programs guide has implementations of the common data-structure operations that interviewers often test.
9. What is the difference between String, StringBuilder, and StringBuffer?
String | StringBuffer | StringBuilder | |
|---|---|---|---|
| Mutable? | No | Yes | Yes |
| Thread-safe? | Yes | Yes (synchronized) | No |
| Performance | Slowest for concatenation loops | Moderate | Fastest |
| Typical use case | Fixed or rarely-changed text | Multi-threaded string building | Single-threaded string building |
For repeated concatenation in a loop, use StringBuilder. Concatenating String objects inside a loop creates a new object on every iteration, which gets expensive with large data.
10. What is the difference between HashMap and Hashtable?
| Feature | HashMap | Hashtable |
|---|---|---|
| Synchronization | Not synchronized | Synchronized (thread-safe) |
| Null keys and values | 1 null key, multiple null values | Neither null keys nor null values |
| Performance | Faster | Slower due to synchronization overhead |
| Current recommendation | Preferred | Legacy; largely superseded |
In modern Java code, if you need a thread-safe map, prefer ConcurrentHashMap over Hashtable. Hashtable dates from Java 1.0 and carries legacy design decisions that ConcurrentHashMap corrects.
What These Patterns Look Like in AI-Era Development
Java’s abstract class and interface design from Q6 appears in every major Python LLM framework. LangChain’s BaseLLM, AutoGen’s Agent protocol, and LlamaIndex’s BaseQueryEngine all use the same contract: define abstract methods, let concrete subclasses override them for specific provider behavior. The OOP fundamentals covered here transfer directly across languages.
If you want to see how that plays out when building an actual AI application, TinkerLLM is worth testing at ₹299. It gives you access to real LLM APIs so you can build before committing to a longer programme.
Primary sources
Frequently asked questions
Is Java still asked in IT company placement interviews in 2026?
Yes. Service-tier companies like Infosys, HCL, Wipro, and Cognizant consistently test core Java in their technical rounds. Product companies have moved more toward Python and Go for AI roles, but OOP fundamentals remain relevant across the board.
What is the difference between JDK, JRE, and JVM in one line?
JVM runs bytecode; JRE provides libraries plus JVM; JDK provides compiler plus tools plus JRE. You need JDK to write and compile Java; you need JRE to run a compiled Java program.
Do I need to know multithreading for a fresher Java interview?
For most IT service companies, knowing how to create a thread (extending Thread or implementing Runnable) is enough. Product companies sometimes probe synchronized blocks, wait/notify, and thread pools in technical rounds.
Which Java version should I prepare for in 2026?
Java 11 or Java 17 LTS covers everything interviewers ask at the fresher level. Java 8 topics such as lambda expressions and the stream API still appear in service-tier company technical screens.
How many Java questions appear in a typical fresher technical round?
Expect five to ten concept questions in a thirty to forty-five minute technical interview. OOP principles, exception handling, and collections appear most consistently across companies.
A self-paced playground for building with LLMs.
TinkerLLM is FACE Prep's sister property. A guided environment for shipping real LLM applications, the kind of project that earns a paragraph on your resume, not a line.
Try TinkerLLM (₹299 launch)