Java HR Interview Q&A (Basic → Advanced)
Basic Level (Core Fundamentals)
Q1. Can you explain Java in simple terms?
A: Java is a high-level, object-oriented, platform-independent programming language. It follows
the “Write Once, Run Anywhere” principle because code runs on the Java Virtual Machine
(JVM).
Q2. What are the main features of Java?
A: Platform independence, object-oriented, robust, secure, simple, multithreaded, and has
automatic memory management via garbage collection.
Q3. What’s the difference between JDK, JRE, and JVM?
A:
JDK – Java Development Kit (tools + compiler + JRE)
JRE – Java Runtime Environment (libraries + JVM)
JVM – Java Virtual Machine (runs bytecode)
Q4. What are Java’s data types?
A: Two categories:
Primitive – int, double, char, boolean, etc.
Non-primitive – Strings, arrays, classes, objects.
Q5. What is the difference between == and .equals()?
A: == compares memory references, .equals() compares object values (if overridden).
Intermediate Level (OOPs & Practical Use)
Q6. Can you explain the main pillars of OOP in Java?
A:
Encapsulation – wrapping data & methods together
Inheritance – acquiring properties of another class
Polymorphism – many forms (method overloading & overriding)
Abstraction – hiding implementation details, showing only functionality
Q7. What’s the difference between abstract class and interface?
A:
Abstract class → can have abstract & non-abstract methods, supports inheritance
Interface → all methods are abstract (Java 7), supports multiple inheritance
Q8. What is method overloading vs overriding?
A:
Overloading – same method name, different parameters (compile-time).
Overriding – same method name, same parameters in child class (runtime).
Q9. What is the final keyword used for?
A: To make variables constant, prevent method overriding, and prevent class inheritance.
Q10. What is exception handling in Java?
A: Mechanism to handle runtime errors using try-catch-finally, throws, and throw.
Advanced Level (Memory, Performance & Best Practices)
Q11. What is garbage collection in Java?
A: Automatic process where JVM removes unused objects to free memory.
Q12. What are String, StringBuilder, and StringBuffer?
A:
String → immutable
StringBuilder → mutable, faster, not thread-safe
StringBuffer → mutable, thread-safe
Q13. What is multithreading in Java?
A: Running multiple tasks at the same time using threads to improve performance.
Q14. What is the difference between ArrayList and LinkedList?
A:
ArrayList → fast random access, slower insert/delete in middle
LinkedList → faster insert/delete, slower access
Q15. How do you make a class immutable in Java?
A: Declare class final, make fields private & final, provide only getters (no setters).
Q16. What is the difference between HashMap and Hashtable?
A:
HashMap → not synchronized, allows null keys/values
Hashtable → synchronized, no null keys/values
Q17. What is the difference between throw and throws?
A:
throw → used to throw an exception
throws → used in method signature to declare exceptions
Q18. What is the difference between checked and unchecked exceptions?
A:
Checked → checked at compile-time (IOException)
Unchecked → checked at runtime (NullPointerException)
Q19. What is the difference between shallow copy and deep copy?
A:
Shallow copy → copies object reference only
Deep copy → copies the object and its data completely
Q20. How do you optimize Java code for better performance?
A: Use efficient algorithms, avoid unnecessary object creation, prefer StringBuilder for
concatenation, use collections properly, and minimize synchronization overhead.
Basic Level
1. What is Java?
A high-level, object-oriented, platform-independent programming language that runs on the Java
Virtual Machine (JVM).
2. Features of Java?
Platform independence, object-oriented, secure, robust, multithreaded, portable, automatic
memory management.
3. Difference between JDK, JRE, and JVM?
JDK – Java Development Kit (compiler + tools + JRE)
JRE – Java Runtime Environment (libraries + JVM)
JVM – Runs Java bytecode.
4. Data types in Java?
Primitive → byte, short, int, long, float, double, char, boolean
Non-primitive → Strings, arrays, classes, objects.
5. == vs .equals()?
== → compares memory reference
.equals() → compares object values (if overridden).
Intermediate Level
6. OOP Pillars?
Encapsulation, Inheritance, Polymorphism, Abstraction.
7. Abstract class vs Interface?
Abstract → abstract + concrete methods, single inheritance
Interface → all abstract (Java 7), supports multiple inheritance.
8. Overloading vs Overriding?
Overloading → compile-time, different parameters
Overriding → runtime, same parameters.
9. final keyword?
Used to make constants, prevent method overriding, stop class inheritance.
10. Exception handling?
Managing runtime errors using try, catch, finally, throw, and throws.
Advanced Level
11. Garbage collection?
JVM automatically deletes unused objects to free memory.
12. String vs StringBuilder vs StringBuffer?
String → immutable
StringBuilder → mutable, faster, not thread-safe
StringBuffer → mutable, thread-safe.
13. Multithreading?
Running multiple tasks simultaneously for better CPU usage.
14. ArrayList vs LinkedList?
ArrayList → fast random access, slower insertion/deletion in middle
LinkedList → slower access, faster insertion/deletion.
15. Immutable class creation?
Declare final class, private final fields, no setters, only getters.
16. HashMap vs Hashtable?
HashMap → not synchronized, allows nulls
Hashtable → synchronized, no nulls allowed.
17. throw vs throws?
throw → to throw an exception
throws → to declare exceptions in method signature.
18. Checked vs Unchecked exceptions?
Checked → checked at compile-time
Unchecked → checked at runtime.
19. Shallow vs Deep copy?
Shallow → copies reference only
Deep → copies object and its contents fully.
20. Java code optimization?
Use efficient algorithms, fewer objects, StringBuilder for concatenation, optimize collections,
reduce synchronization.
Extra Technical Q&A
21. Constructor?
Special method to initialize objects.
22. Default constructor?
Provided by compiler if no constructor is defined.
23. this vs super?
this → refers to current object
super → refers to parent class object.
24. static keyword?
Belongs to class, shared among all objects.
25. transient keyword?
Prevents a variable from being serialized.
26. volatile keyword?
Tells JVM that variable may be modified by multiple threads.
27. synchronized keyword?
Ensures thread-safe access to a method/block.
28. Serialization?
Converting object to byte stream for storage or transfer.
29. Deserialization?
Converting byte stream back to object.
30. Java Collections Framework?
Set of classes/interfaces (List, Set, Map) for storing/managing data.
31. LinkedHashMap vs TreeMap?
LinkedHashMap → maintains insertion order
TreeMap → stores keys in sorted order.
32. PriorityQueue?
A queue where elements are ordered by priority.
33. Comparable vs Comparator?
Comparable → natural ordering (compareTo)
Comparator → custom ordering (compare).
34. Lambda expression?
Short way to write a functional interface implementation:
(a, b) -> a + b;
35. Functional interface?
Interface with exactly one abstract method (e.g., Runnable).
36. Stream API?
Functional operations (map, filter, reduce) on collections.
37. Optional class?
Container object to avoid null checks.
38. var keyword (Java 10)?
Local variable type inference.
39. Records (Java 14)?
Compact syntax for immutable data classes.
40. Modules (Java 9)?
Helps organize code into reusable, independent units.
Most Frequently Asked Java Questions (Basic →
Intermediate)
Basic Level
Q1. What is Java?
Java is a high-level, object-oriented, platform-independent programming language that runs on
JVM.
Q2. Features of Java?
Platform independent, OOP, secure, robust, portable, multithreaded, automatic garbage
collection.
Q3. Difference between JDK, JRE, and JVM?
JDK – Development tools + JRE
JRE – Libraries + JVM
JVM – Runs Java bytecode
Q4. Data types in Java?
Primitive → byte, short, int, long, float, double, char, boolean
Non-primitive → String, arrays, objects.
Q5. Difference between == and .equals()?
== → compares memory reference
.equals() → compares values.
Q6. What are the four pillars of OOP?
Encapsulation, Inheritance, Polymorphism, Abstraction.
Q7. What is a constructor?
A special method used to initialize objects.
Q8. Difference between default constructor and parameterized constructor?
Default → no parameters, created automatically if not defined.
Parameterized → accepts arguments to set initial values.
Q9. What is method overloading?
Same method name with different parameters (compile-time polymorphism).
Q10. What is method overriding?
Same method name and parameters in subclass (runtime polymorphism).
Intermediate Level
Q11. Abstract class vs Interface?
Abstract → abstract + concrete methods, single inheritance.
Interface → all abstract (Java 7), supports multiple inheritance.
Q12. What is final keyword used for?
To make constants, prevent method overriding, and stop class inheritance.
Q13. What is exception handling?
Managing runtime errors using try, catch, finally, throw, and throws.
Q14. Checked vs Unchecked exceptions?
Checked → compile-time (IOException)
Unchecked → runtime (NullPointerException)
Q15. Difference between ArrayList and LinkedList?
ArrayList → fast random access, slower insert/delete
LinkedList → slow access, faster insert/delete
Q16. String vs StringBuilder vs StringBuffer?
String → immutable
StringBuilder → mutable, not thread-safe
StringBuffer → mutable, thread-safe
Q17. What is the static keyword?
Belongs to the class instead of instance, shared across objects.
Q18. What is multithreading?
Running multiple threads simultaneously for efficiency.
Q19. What is synchronization?
Controlling access to resources by multiple threads to avoid conflicts.
Q20. What is the difference between throw and throws?
throw → used to throw an exception
throws → declares exceptions a method can throw.