Java Interview Questions & Answers

Top questions asked in interviews for freshers & experienced developers

1. What is Java?
Java is a high-level, object-oriented, platform-independent programming language.
2. Why is Java platform independent?
Because Java code runs on JVM using bytecode, not directly on OS.
3. What is JVM?
JVM is Java Virtual Machine that executes Java bytecode.
4. What is JDK?
JDK is Java Development Kit used to develop Java applications.
5. What is JRE?
JRE provides libraries and JVM to run Java programs.
6. What are features of Java?
Simple, object-oriented, secure, portable, robust, multithreaded.
7. What is OOP?
Object-Oriented Programming organizes code using objects and classes.
8. What is a class?
A class is a blueprint for creating objects.
9. What is an object?
An object is an instance of a class.
10. What is inheritance?
Inheritance allows one class to acquire properties of another class.
11. What is polymorphism?
Polymorphism allows methods to behave differently for different objects.
12. What is encapsulation?
Encapsulation binds data and methods together and hides details.
13. What is abstraction?
Abstraction hides implementation and shows only essential features.
14. What is constructor?
A constructor initializes objects when they are created.
15. Difference between abstract class and interface?
Abstract class can have methods with body, interface cannot.
16. What is method overloading?
Multiple methods with same name but different parameters.
17. What is method overriding?
Redefining a parent class method in child class.
18. What is final keyword?
final prevents modification of variables, methods, or classes.
19. What is static keyword?
static belongs to class, not objects.
20. What is this keyword?
this refers to the current object.
21. What is super keyword?
super refers to parent class object.
22. What are access modifiers?
public, private, protected, and default.
23. What is package?
A package groups related classes and interfaces.
24. What is exception?
An exception is an unexpected event during execution.
25. What is exception handling?
Handling runtime errors using try, catch, finally.
26. Difference between checked and unchecked exceptions?
Checked are compile-time, unchecked are runtime exceptions.
27. What is throw keyword?
throw is used to explicitly throw an exception.
28. What is throws keyword?
throws declares exceptions in method signature.
29. What is multithreading?
Executing multiple threads simultaneously.
30. What is thread?
A thread is a lightweight process.
31. What is synchronization?
It controls access of multiple threads to shared resources.
32. What is deadlock?
A situation where threads wait indefinitely for resources.
33. What is collection framework?
It provides classes and interfaces to store and manipulate data.
34. Difference between List and Set?
List allows duplicates, Set does not.
35. Difference between ArrayList and LinkedList?
ArrayList uses array, LinkedList uses doubly linked list.
36. Difference between HashMap and Hashtable?
HashMap is non-synchronized, Hashtable is synchronized.
37. What is iterator?
Iterator is used to traverse collection elements.
38. What is generics?
Generics provide type safety at compile time.
39. What is wrapper class?
Wrapper classes convert primitive types into objects.
40. What is autoboxing?
Automatic conversion of primitive to object.
41. What is unboxing?
Automatic conversion of object to primitive.
42. What is String in Java?
String is an immutable sequence of characters.
43. Difference between String and StringBuilder?
String is immutable, StringBuilder is mutable.
44. What is memory management?
Java manages memory automatically using garbage collection.
45. What is garbage collection?
Automatic removal of unused objects from memory.
46. What is JVM memory areas?
Heap, Stack, Method Area, PC Register, Native Method Stack.
47. What is finalize() method?
Called before object is garbage collected.
48. What is serialization?
Converting object into byte stream.
49. What is deserialization?
Converting byte stream back into object.
50. What is JDBC?
JDBC is used to connect Java applications with databases.
51. What is JDBC driver?
It enables Java to communicate with database.
52. What is SQL injection?
A security attack using malicious SQL queries.
53. What is Spring?
Spring is a powerful Java framework for enterprise applications.
54. What is Spring Boot?
Spring Boot simplifies Spring application development.
55. What is REST API?
REST is an architectural style for web services.
56. What is Maven?
Maven is a build automation and dependency management tool.
57. What is Gradle?
Gradle is a flexible build automation tool.
58. What is Java 8 feature?
Lambda expressions, streams, functional interfaces.
59. What is lambda expression?
A concise way to represent anonymous functions.
60. What is stream API?
Stream API processes collections in functional style.