Placement Prep

Core Java Interview Questions for Freshers (With Answers)

Thirty core Java interview questions with answers covering OOP, Collections, Exception Handling, and Multithreading. Built for service-tier technical interviews.

By FACE Prep Team 8 min read
java interview-questions placement-prep oop collections freshers

Java questions appear in the technical rounds at TCS, Infosys, Capgemini, and Wipro for both CSE and non-CSE freshers.

This is the question bank the original FACE Prep page promised: 30 questions, grouped by topic, with answers calibrated for what interviewers actually want to hear.

Java Basics

These questions test whether you understand what Java is and how it runs. Interviewers use them to filter candidates quickly in the opening minutes.

  • Q1: What is the difference between JDK, JRE, and JVM?

  • Answer: JVM (Java Virtual Machine) converts bytecode to machine code and is platform-specific. JRE (Java Runtime Environment) bundles JVM with the standard libraries needed to run Java programs. JDK (Java Development Kit) adds the compiler and development tools on top of JRE, giving you the complete toolkit for writing Java programs.

  • Q2: Why is Java platform-independent?

  • Answer: Java source code compiles to bytecode, not native machine code. This bytecode runs on the JVM, and JVMs exist for every major operating system. The same .class file runs on Windows, Linux, or macOS without recompilation.

  • Q3: Why is Java not a purely object-oriented language?

  • Answer: Java has eight primitive data types (int, double, boolean, char, byte, short, long, float) that are not objects. It also allows static members to be accessed without creating an object. A purely OOP language treats everything as an object; Java makes that compromise for performance.

  • Q4: Why is main() declared static in Java?

  • Answer: Static methods can be called without creating an object. Since JVM must invoke main() before any object exists, main() must be static. A non-static main() would require JVM to instantiate the class first, which creates a circular dependency.

  • Q5: What is the String pool in Java?

  • Answer: The String pool is a reserved area in the heap where Java stores string literals. When you write String s = "hello", Java checks whether “hello” already exists in the pool and reuses it if it does. Using new String("hello") bypasses the pool and always creates a fresh heap object.

String s1 = "FACEPrep";
String s2 = "FACEPrep";
String s3 = new String("FACEPrep");
System.out.println(s1 == s2);  // true  (same pool reference)
System.out.println(s1 == s3);  // false (different heap objects)
  • Q6: What is a wrapper class in Java?

  • Answer: Wrapper classes (Integer, Double, Boolean, Character, etc.) convert primitive types into objects. Collections like ArrayList store objects, not primitives, so you pass an Integer instead of an int. Java’s autoboxing handles the conversion automatically since Java 5.

  • Q7: What is the difference between StringBuilder and StringBuffer?

  • Answer: Both create mutable strings, unlike the immutable String class. StringBuffer is thread-safe because its methods are synchronized; StringBuilder is not thread-safe but is faster in single-threaded code. Use StringBuilder by default and switch to StringBuffer only when multiple threads share the same instance.

  • Q8: What is garbage collection in Java?

  • Answer: Garbage collection is the JVM’s automatic process of reclaiming memory held by objects with no live references. In C you call free(); in C++ you call delete. Java’s garbage collector runs as a background daemon thread, so you never manage heap memory manually.

OOP Concepts

OOP questions test whether you can reason about class design, not just recite definitions. Pair this section with FACE Prep’s 20 most-asked data structures interview questions to cover the two topics most technical rounds rely on.

  • Q9: What are the four pillars of OOP?

  • Answer: Encapsulation (hiding data behind methods), Inheritance (deriving behaviour from a parent class), Polymorphism (same interface, different behaviour depending on context), and Abstraction (exposing what an object does, not how it does it).

  • Q10: What is the difference between method overloading and method overriding?

  • Answer: Overloading defines multiple methods with the same name but different parameter lists in the same class; the compiler resolves the call at compile time. Overriding provides a new implementation of a parent class method in a subclass; the JVM resolves the call at runtime. Both are forms of polymorphism.

  • Q11: What is the difference between equals() and == in Java?

  • Answer: == compares references (memory addresses) for objects, or values for primitives. equals() compares the content of objects. For String, two separate new String("hello") instances are == false but equals() true.

String a = new String("hello");
String b = new String("hello");
System.out.println(a == b);       // false (different objects)
System.out.println(a.equals(b));  // true  (same content)

The Oracle Java SE API documentation specifies that String.equals() performs a character-by-character comparison.

  • Q12: What is the difference between an abstract class and an interface?

  • Answer: An abstract class can have instance variables, constructors, and both abstract and concrete methods. An interface before Java 8 could only have abstract methods and constants. From Java 8 onward, interfaces support default and static methods. A class can extend only one abstract class but implement multiple interfaces.

  • Q13: What does the final keyword do in Java?

  • Answer: Applied to a variable: its value cannot be changed after the first assignment. Applied to a method: it cannot be overridden in a subclass. Applied to a class: it cannot be extended. The String class in Java’s standard library is declared final.

  • Q14: What is the difference between this and super in Java?

  • Answer: this refers to the current class instance; super refers to the parent class. this() calls the current class’s constructor and super() calls the parent’s. Both must be the first statement in a constructor, so they cannot appear together in the same constructor.

  • Q15: Why does Java not support multiple inheritance for classes?

  • Answer: Multiple class inheritance creates the Diamond Problem: if two parent classes define the same method, the compiler cannot determine which version the child class should inherit. Java avoids this by allowing a class to extend only one class. Multiple interfaces can be implemented to achieve comparable flexibility.

Exception Handling

Exception handling appears consistently in Capgemini and Infosys technical rounds, often as output-prediction questions. For how company-specific technical rounds structure these topics, see FACE Prep’s Siemens technical and HR interview guide.

  • Q16: What is the difference between final, finally, and finalize?

  • Answer: final is a keyword applied to variables, methods, or classes (see Q13). finally is an exception-handling block that executes whether or not an exception occurred or was caught. finalize() is a method the garbage collector calls before reclaiming an object’s memory; it was deprecated in Java 9.

  • Q17: What is the difference between checked and unchecked exceptions?

  • Answer: Checked exceptions are verified by the compiler: your code must either catch them with try-catch or declare them with throws in the method signature (e.g., IOException, SQLException). Unchecked exceptions extend RuntimeException and are not enforced by the compiler (e.g., NullPointerException, ArrayIndexOutOfBoundsException).

  • Q18: What is the difference between throw and throws?

  • Answer: throw is used inside a method body to explicitly throw an exception object, for example throw new IllegalArgumentException("invalid input"). throws appears in a method signature to declare that the method may produce a checked exception, alerting the caller to handle or propagate it.

  • Q19: Can the finally block be skipped?

  • Answer: In normal execution, finally runs whether an exception occurs or not. The two situations where it does not execute: System.exit() is called inside the try or catch block, or the JVM itself crashes. All other flows, caught and uncaught exceptions included, execute finally.

  • Q20: How do you create a custom exception in Java?

  • Answer: Define a class that extends Exception (for a checked exception) or RuntimeException (for an unchecked one). Add a constructor that accepts a message string and passes it to the parent via super(message). Throw it with throw new YourException("message"). Custom exceptions make domain-specific errors readable in stack traces.

Collections Framework

Collections questions are a fixture of Infosys and Wipro technical rounds, particularly the differences between List, Set, and Map. For deeper implementation details, Baeldung’s Java Collections Guide covers the internals that interviewers sometimes probe. For how HP structures its technical rounds across these topics, see the HP interview process guide.

  • Q21: What is the difference between ArrayList and LinkedList?

  • Answer: Both implement List. ArrayList is backed by a resizable array: random access via get(i) is O(1), but middle insertions and deletions are slow. LinkedList is a doubly-linked list: insertions and deletions at both ends are O(1), but random access is O(n).

  • Q22: What is the difference between HashMap and HashSet?

  • Answer: HashMap stores key-value pairs. HashSet stores only unique values with no associated value. Internally, HashSet is backed by a HashMap where the stored element is the key and a constant dummy object is the value.

  • Q23: What is the difference between List and Set?

  • Answer: List preserves insertion order and allows duplicate elements. Set does not allow duplicates and may or may not preserve order: HashSet does not preserve order, LinkedHashSet does, and TreeSet maintains sorted order.

  • Q24: What is the difference between Iterator and a for-each loop?

  • Answer: Both traverse a collection. Iterator gives explicit control: you can call remove() to delete elements during traversal without triggering a ConcurrentModificationException. A for-each loop is cleaner syntax but cannot safely remove elements while iterating.

  • Q25: What is the contract between hashCode() and equals()?

  • Answer: If two objects are equal by equals(), they must return the same hashCode(). The reverse is not required: two objects can share a hash code without being equal (hash collision). Breaking this contract produces silent bugs in HashMap and HashSet, which use hashCode() for bucket placement and equals() to resolve collisions.

Multithreading

Multithreading questions are less common in entry-level technical rounds but appear in Wipro NLTH and higher-band TCS Digital interviews.

  • Q26: What are the two ways to create a thread in Java?

  • Answer: Extend the Thread class and override run(), or implement the Runnable interface and pass the instance to a Thread constructor. The Runnable approach is preferred because Java supports single inheritance only, so implementing Runnable leaves your class free to extend another class.

  • Q27: What does synchronized do in Java?

  • Answer: synchronized ensures that only one thread executes a method or block on a given object at a time. It prevents race conditions when multiple threads read and write shared data. The cost is added overhead and potential thread contention.

  • Q28: What is a deadlock?

  • Answer: Deadlock occurs when two or more threads are each waiting for a lock held by the other, and neither can proceed. Thread A holds lock X and waits for lock Y; Thread B holds lock Y and waits for lock X. The JVM does not automatically resolve deadlocks, so the affected threads freeze permanently.

  • Q29: What is the difference between sleep() and wait()?

  • Answer: Thread.sleep(ms) pauses the current thread for a set duration without releasing any locks it holds. Object.wait() pauses the thread and releases the object’s monitor lock, allowing other synchronized threads to proceed. wait() must be called from within a synchronized block; sleep() does not require one.

  • Q30: What is the difference between start() and run() on a Thread?

  • Answer: Calling run() directly executes the method body in the current thread; no new thread is created. Calling start() creates a new OS-level thread and then invokes run() on it. Calling run() instead of start() is one of the most common output-prediction traps in Java technical rounds.

Clearing the five topic areas above is the Java prep that gets you through a service-tier technical round. The next question recruiters ask is what you have actually built. TinkerLLM puts real LLM API calls in your hands for ₹299, and the micro-project you build with it is the kind of evidence that answers that question concretely.

Primary sources

Frequently asked questions

How many Java questions come up in TCS NQT technical round?

TCS NQT's technical section tests Java syntax, OOP principles, and output-prediction questions. This list covers all the core topics. Advanced Java frameworks like Spring and Hibernate are not required for the fresher technical section.

Is core Java different from advanced Java for interviews?

Core Java covers the language fundamentals tested in most fresher interviews: OOP, Collections, Exception Handling, and Multithreading. Advanced Java (Servlets, JSP, Hibernate) is rarely tested at the fresher level unless the job description explicitly mentions it.

What is the difference between JDK, JRE, and JVM?

JVM (Java Virtual Machine) runs bytecode. JRE (Java Runtime Environment) includes JVM plus the standard libraries needed to run a program. JDK (Java Development Kit) includes JRE plus the compiler and tools needed to develop Java programs.

Can non-CSE branches be asked Java interview questions?

Yes. TCS, Infosys, and Capgemini hire from ECE, EEE, and Mech branches for technology roles, and their technical rounds often include basic Java or C++ questions. Core Java fundamentals are the right preparation regardless of branch.

How should I practice Java before a technical interview?

Work through this question list to cover the theory first, then write and compile each code example yourself. Output-prediction questions are common in technical rounds, and running the code yourself builds pattern recognition faster than re-reading answers.

Is String a primitive or an object in Java?

String is an object in Java, not a primitive. It is an instance of the java.lang.String class and is stored in the String pool area of the heap. This is why equals() and == behave differently when comparing two String values.

Build AI projects

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)
Free AI Roadmap PDF