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.
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
.classfile 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()declaredstaticin 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-staticmain()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. Usingnew 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 likeArrayListstore objects, not primitives, so you pass anIntegerinstead of anint. Java’s autoboxing handles the conversion automatically since Java 5. -
Q7: What is the difference between
StringBuilderandStringBuffer? -
Answer: Both create mutable strings, unlike the immutable
Stringclass.StringBufferis thread-safe because its methods are synchronized;StringBuilderis not thread-safe but is faster in single-threaded code. UseStringBuilderby default and switch toStringBufferonly 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 calldelete. 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. ForString, two separatenew String("hello")instances are==false butequals()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
defaultandstaticmethods. A class can extend only one abstract class but implement multiple interfaces. -
Q13: What does the
finalkeyword 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
Stringclass in Java’s standard library is declaredfinal. -
Q14: What is the difference between
thisandsuperin Java? -
Answer:
thisrefers to the current class instance;superrefers to the parent class.this()calls the current class’s constructor andsuper()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, andfinalize? -
Answer:
finalis a keyword applied to variables, methods, or classes (see Q13).finallyis 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-catchor declare them withthrowsin the method signature (e.g.,IOException,SQLException). Unchecked exceptions extendRuntimeExceptionand are not enforced by the compiler (e.g.,NullPointerException,ArrayIndexOutOfBoundsException). -
Q18: What is the difference between
throwandthrows? -
Answer:
throwis used inside a method body to explicitly throw an exception object, for examplethrow new IllegalArgumentException("invalid input").throwsappears 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
finallyblock be skipped? -
Answer: In normal execution,
finallyruns whether an exception occurs or not. The two situations where it does not execute:System.exit()is called inside thetryorcatchblock, or the JVM itself crashes. All other flows, caught and uncaught exceptions included, executefinally. -
Q20: How do you create a custom exception in Java?
-
Answer: Define a class that extends
Exception(for a checked exception) orRuntimeException(for an unchecked one). Add a constructor that accepts a message string and passes it to the parent viasuper(message). Throw it withthrow 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
ArrayListandLinkedList? -
Answer: Both implement
List.ArrayListis backed by a resizable array: random access viaget(i)is O(1), but middle insertions and deletions are slow.LinkedListis 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
HashMapandHashSet? -
Answer:
HashMapstores key-value pairs.HashSetstores only unique values with no associated value. Internally,HashSetis backed by aHashMapwhere the stored element is the key and a constant dummy object is the value. -
Q23: What is the difference between
ListandSet? -
Answer:
Listpreserves insertion order and allows duplicate elements.Setdoes not allow duplicates and may or may not preserve order:HashSetdoes not preserve order,LinkedHashSetdoes, andTreeSetmaintains sorted order. -
Q24: What is the difference between
Iteratorand a for-each loop? -
Answer: Both traverse a collection.
Iteratorgives explicit control: you can callremove()to delete elements during traversal without triggering aConcurrentModificationException. A for-each loop is cleaner syntax but cannot safely remove elements while iterating. -
Q25: What is the contract between
hashCode()andequals()? -
Answer: If two objects are equal by
equals(), they must return the samehashCode(). The reverse is not required: two objects can share a hash code without being equal (hash collision). Breaking this contract produces silent bugs inHashMapandHashSet, which usehashCode()for bucket placement andequals()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
Threadclass and overriderun(), or implement theRunnableinterface and pass the instance to aThreadconstructor. TheRunnableapproach is preferred because Java supports single inheritance only, so implementingRunnableleaves your class free to extend another class. -
Q27: What does
synchronizeddo in Java? -
Answer:
synchronizedensures 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()andwait()? -
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 asynchronizedblock;sleep()does not require one. -
Q30: What is the difference between
start()andrun()on a Thread? -
Answer: Calling
run()directly executes the method body in the current thread; no new thread is created. Callingstart()creates a new OS-level thread and then invokesrun()on it. Callingrun()instead ofstart()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.
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)