Skip to content

Java interview questions for freshers, with answers

The Java questions freshers actually face: OOP, collections, JVM and coding rounds, with short answers and a 7-day prep plan.

5 min read
Illustration of a desk with a laptop showing code, a steaming coffee cup and a notebook

Java interview questions for freshers follow a predictable pattern: OOP concepts, collections, a little JVM internals, and one or two coding problems on strings or arrays. Service companies hiring in bulk (TCS, Infosys, Wipro, Accenture) and product startups both pull from the same core list - what changes is depth. This guide covers the questions freshers actually get asked, with short answers you can adapt, and a prep plan at the end.

Core Java questions

1. Why is Java called platform-independent? Java compiles to bytecode, not machine code. The JVM on each operating system runs that same bytecode, so one compiled program runs anywhere a JVM exists - "write once, run anywhere".

2. What is the difference between JDK, JRE and JVM? The JVM runs bytecode. The JRE is the JVM plus the libraries needed to run programs. The JDK is the JRE plus the compiler and tools you need to write and build programs.

3. Why is Java not 100% object-oriented? Because of primitive types (int, char, boolean and so on), which are not objects. Wrapper classes like Integer exist, but primitives themselves are not objects.

4. What is the difference between == and .equals()? == compares references (do two variables point to the same object). .equals() compares content, if the class overrides it. The classic trap: two String objects with the same text can be == false but .equals() true.

5. Why are Strings immutable in Java? Security, thread safety and caching. Immutability lets the JVM pool string literals safely and makes String safe to use as a HashMap key.

OOP questions (the section everyone gets)

6. Explain the four pillars of OOP.

  • Encapsulation: bundling data with the methods that operate on it, and hiding internal state behind getters/setters.
  • Inheritance: a class acquiring fields and methods from a parent class with extends.
  • Polymorphism: one method name, many behaviours - compile-time (overloading) and runtime (overriding).
  • Abstraction: exposing only what callers need and hiding the how, via abstract classes and interfaces.

7. Method overloading vs overriding? Overloading: same name, different parameters, decided at compile time, within one class. Overriding: same signature in a subclass, decided at runtime.

8. Abstract class vs interface? An abstract class can have constructors, instance variables and some implemented methods. An interface is a contract - methods are abstract by default (with default and static methods allowed since Java 8), and a class can implement many interfaces but extend only one class.

9. What is the super keyword? It refers to the parent class - used to call the parent's constructor, methods or variables from the subclass.

Collections questions

10. ArrayList vs LinkedList? ArrayList is backed by a dynamic array - fast random access (O(1) get), slow middle inserts. LinkedList is nodes with pointers - fast insert/delete at the ends, slow access (O(n)). In practice freshers should default to ArrayList.

11. HashMap vs Hashtable? HashMap is not synchronized, allows one null key and null values, and is what everyone uses. Hashtable is synchronized and legacy. For thread safety today, use ConcurrentHashMap.

12. How does a HashMap work internally? It stores entries in buckets based on the key's hashCode. Collisions are handled with a linked list (converted to a balanced tree when a bucket grows large, since Java 8). get() and put() are O(1) on average.

13. HashSet vs TreeSet? HashSet is unordered with O(1) operations. TreeSet keeps elements sorted (O(log n)) and needs comparable elements.

JVM, memory and exceptions

14. What is garbage collection? The JVM automatically frees memory used by objects no longer referenced. You can request it with System.gc() but cannot force it.

15. Stack vs heap memory? The heap stores objects; the stack stores method calls and local variables per thread. Objects live on the heap, references to them on the stack.

16. Checked vs unchecked exceptions? Checked exceptions (IOException, SQLException) must be declared or caught at compile time. Unchecked ones (NullPointerException, ArrayIndexOutOfBoundsException) are runtime failures, usually programming bugs.

17. final, finally and finalize? final: a keyword making a variable constant, a method non-overridable, or a class non-inheritable. finally: a block that runs after try/catch, exception or not. finalize: a deprecated pre-garbage-collection callback - do not rely on it.

Coding questions freshers get

Most fresher rounds include one live coding problem. Practice these until you can write them without hesitation:

  • Reverse a string (and explain why you would use StringBuilder)
  • Check palindrome
  • Count duplicate characters or words in a string
  • Find the second-largest number in an array
  • FizzBuzz and simple pattern printing
  • Fibonacci - iterative and recursive (and why recursion is slower here)

Interviewers care more about you narrating your approach than a perfect answer. Talk through edge cases out loud.

Company-specific notes for Indian freshers

Service companies hiring through NQT, off-campus drives and campus placements lean heavily on OOP definitions plus one easy coding question. Product startups skip definitions and go straight to coding and a project deep-dive - expect "explain your final year project's architecture". Either way, your resume decides which questions you get: keep it tight with our software engineer resume format, and check it against ATS rules with the resume ATS checker.

Database and SQL rounds usually travel with the Java round - our SQL interview questions guide covers that side. For daily practice, the Cheatcode interview question bank has role-wise sets.

A 7-day prep plan

  • Days 1-2: OOP + core Java definitions, with one example each you can code from memory.
  • Days 3-4: Collections - ArrayList, HashMap, HashSet internals.
  • Day 5: Exceptions, memory, Java 8 features (streams, lambdas) at a talking level.
  • Days 6-7: Two coding problems a day from the list above, spoken aloud as you solve. Mock rounds help: how to do a mock interview.

Frequently asked questions

Is Java enough to get a fresher job in India?

Java plus SQL plus one project you can explain deeply covers most service-company and many startup fresher roles. Add basic DSA for product companies.

Which Java version should I prepare?

Know Java 8 features well (streams, lambdas, Optional) and be aware of what newer LTS versions (17, 21) added. Most Indian companies still run Java 8 to 17 in production.

Do freshers get asked multithreading?

At service companies, rarely beyond "what is a thread". Product companies may ask about synchronization, the volatile keyword and deadlocks - prepare these three at a talking level.

How many questions should I prepare?

Fifty solid answers with examples beat 200 memorised lines. The questions in this guide cover the core of most fresher rounds.

Should I learn Spring Boot for fresher interviews?

Only if a project on your resume uses it - then you must explain it end to end. Core Java mastery matters more than framework name-dropping at this stage.

Sources

Found this useful? Send it on.

WhatsAppLinkedIn

Keep reading