Beginner to Intermediate Level
1. What is JVM?
JVM (Java Virtual Machine) is an engine that provides a runtime environment to drive Java applications. It converts Java bytecode into machine language.
2. What is the difference between JDK, JRE, and JVM?
- JDK: Java Development Kit – includes tools for developing, debugging, and monitoring Java applications.
- JRE: Java Runtime Environment – includes JVM + libraries to run Java applications.
- JVM: Executes Java bytecode.
3. What are the primitive data types in Java?
byte, short, int, long, float, double, char, boolean.
4. What is the default value of an int variable in Java?
0
5. Explain the concept of OOP.
Object-Oriented Programming is a paradigm based on the concept of objects, which encapsulate data and behavior. Java supports OOP principles like Encapsulation, Inheritance, Polymorphism, and Abstraction.
6. What is encapsulation?
Encapsulation is the mechanism of wrapping data (variables) and methods into a single unit called class.
7. What is inheritance?
Inheritance allows a class to acquire the properties and methods of another class.
8. What is polymorphism?
Polymorphism allows one interface to be used for different underlying forms (data types).
9. What is abstraction?
Abstraction is hiding internal implementation and showing only necessary details.
10. What is method overloading?
Method overloading allows multiple methods with the same name but different parameters in a class.
11. What is method overriding?
Method overriding allows a subclass to provide a specific implementation of a method already defined in its superclass.
12. What is a constructor?
A constructor is a special method used to initialize objects.
13. What is the difference between static and non-static methods?
Static methods belong to the class and can be called without creating an object. Non-static methods belong to objects.
14. What is the 'this' keyword?
It refers to the current object inside a method or constructor.
15. What is the 'super' keyword?
Used to call the superclass method or constructor from a subclass.
16. What is the difference between '==' and 'equals()'?
'==' checks reference equality, 'equals()' checks object content equality.
17. What are access modifiers in Java?
public, private, protected, and default – used to set the visibility of classes, methods, and variables.
18. What is an interface?
An interface is a reference type in Java. It is a collection of abstract methods.
19. What is an abstract class?
A class that cannot be instantiated and may have abstract methods.
20. Difference between interface and abstract class?
Interfaces can have only abstract methods (until Java 8), abstract classes can have both abstract and concrete methods.
21. What is a package?
A package is a namespace for organizing classes and interfaces.
22. What is the use of the final keyword?
final can be used with variables (constant), methods (cannot be overridden), and classes (cannot be extended).
23. What is exception handling?
Mechanism to handle runtime errors, using try-catch blocks.
24. What is the difference between checked and unchecked exceptions?
Checked exceptions are checked at compile-time; unchecked are checked at runtime.
25. What is the use of the throw and throws keywords?
throw is used to explicitly throw an exception; throws is used to declare an exception.
26. What is a try-with-resources statement?
A try block that declares one or more resources to be closed automatically.
27. What is the difference between ArrayList and LinkedList?
ArrayList is backed by a dynamic array; LinkedList by a doubly linked list.
28. What is the difference between HashMap and Hashtable?
HashMap is not synchronized; Hashtable is synchronized.
29. What is the difference between List and Set?
List allows duplicates; Set does not.
30. What is the purpose of the Collections class?
It contains static methods for operating on collections.
31. What is autoboxing?
Automatic conversion of primitive types to their corresponding wrapper classes.
32. What is unboxing?
Conversion of wrapper types to their corresponding primitive types.
33. What is a lambda expression?
A short block of code that takes in parameters and returns a value.
34. What is a functional interface?
An interface with only one abstract method.
35. What is the Stream API?
A new abstraction introduced in Java 8 to process sequences of elements.
36. What is immutability?
An object whose state cannot be modified after creation.
37. What is String pool?
A special memory region where string literals are stored.
38. What is the difference between String, StringBuilder, and StringBuffer?
- String: immutable
- StringBuilder: mutable and not thread-safe
- StringBuffer: mutable and thread-safe
39. What is synchronization?
Ensuring that only one thread can access a resource at a time.
40. What is multithreading?
The process of executing multiple threads simultaneously.
41. What is a thread?
A lightweight process or the smallest unit of CPU execution.
42. How to create a thread in Java?
By extending Thread class or implementing Runnable interface.
43. What is the difference between start() and run()?
start() starts a new thread, run() executes in the current thread.
44. What is a deadlock?
A condition where two or more threads are blocked forever, waiting for each other.
45. What is the purpose of the join() method?
It allows one thread to wait until another thread completes execution.
46. What is garbage collection?
Process of reclaiming unused memory automatically.
47. What are wrapper classes?
Classes that convert primitives to objects: Integer, Double, etc.
48. What is type casting?
Converting a variable from one type to another.
49. What is the use of instanceof keyword?
It checks whether an object is an instance of a specific class or subclass.
50. What is the purpose of the main() method?
It is the entry point of a Java application.