1. What is Java?
Java is a high-level, object-oriented programming language developed by Sun Microsystems (now owned by Oracle).
2. What are the features of Java?
Java is platform-independent, object-oriented, secure, robust, multithreaded, and high-performance.
3. What is JVM?
JVM (Java Virtual Machine) is an engine that provides a runtime environment to execute Java bytecode.
4. What is JDK?
JDK (Java Development Kit) is a software development kit used to develop Java applications.
5. What is JRE?
JRE (Java Runtime Environment) is a part of JDK that provides libraries and resources to run Java applications.
6. What is the difference between JDK, JRE, and JVM?
JDK includes JRE and development tools, JRE contains JVM and libraries, and JVM executes Java programs.
7. What is bytecode in Java?
Bytecode is an intermediate code generated by the Java compiler, executed by the JVM.
8. What is an object in Java?
An object is an instance of a class with state and behavior.
9. What is a class in Java?
A class is a blueprint from which objects are created.
10. What are access modifiers in Java?
Access modifiers (public, private, protected, default) define the scope of a variable or method.
11. What is the difference between static and instance variables?
Static variables belong to the class, while instance variables belong to objects.
12. What is method overloading?
Method overloading is defining multiple methods with the same name but different parameters.
13. What is method overriding?
Method overriding allows a subclass to provide a specific implementation of a method defined in its superclass.
14. What is the final keyword in Java?
The final keyword restricts modification of variables, methods, and classes.
15. What is an abstract class?
An abstract class is a class that cannot be instantiated and may contain abstract methods.
16. What is an interface?
An interface is a reference type that defines abstract methods which must be implemented by classes.
17. What is the difference between abstract classes and interfaces?
Abstract classes can have method implementations, while interfaces contain only abstract methods (until Java 8).
18. What is the difference between == and equals()?
== compares references, while equals() compares object values.
19. What is polymorphism in Java?
Polymorphism allows objects to be treated as instances of their parent class.
20. What is inheritance in Java?
Inheritance is a mechanism where a subclass acquires properties and behaviors from a superclass.
21. What are wrapper classes in Java?
Wrapper classes convert primitive types into objects (e.g., Integer, Double).
22. What is exception handling?
Exception handling is managing runtime errors using try, catch, and finally blocks.
23. What is a checked and unchecked exception?
Checked exceptions must be handled, while unchecked exceptions occur at runtime.
24. What is multithreading in Java?
Multithreading allows concurrent execution of two or more threads.
25. What is synchronization?
Synchronization prevents multiple threads from accessing shared resources simultaneously.
26. What is the difference between String, StringBuilder, and StringBuffer?
String is immutable, StringBuilder is mutable and faster, StringBuffer is thread-safe.
27. What is a lambda expression?
Lambda expressions provide a concise way to implement functional interfaces in Java 8.
28. What are Java Streams?
Streams provide functional-style operations on collections.
29. What is garbage collection in Java?
Garbage collection automatically deallocates memory for unused objects.
30. What is the difference between HashMap and HashTable?
HashMap is not synchronized, while Hashtable is synchronized.
31. What is the difference between ArrayList and LinkedList?
ArrayList is better for storing and accessing data, whereas LinkedList is better for manipulating data.
32. What is a HashSet in Java?
HashSet is a collection that does not allow duplicate elements and uses hashing for storage.
33. What is a TreeSet?
TreeSet is a NavigableSet implementation based on a TreeMap, which stores elements in sorted order.
34. What is a PriorityQueue?
PriorityQueue is a queue that orders elements according to their natural ordering or a specified comparator.
35. What is a ConcurrentHashMap?
ConcurrentHashMap is a thread-safe variant of HashMap that allows concurrent access.
36. What is the difference between HashMap and ConcurrentHashMap?
HashMap is not synchronized, whereas ConcurrentHashMap allows thread-safe operations.
37. What are functional interfaces in Java?
Functional interfaces are interfaces with a single abstract method, used in lambda expressions.
38. What is the Stream API in Java?
The Stream API provides a functional programming approach to process collections in a declarative way.
39. What are default and static methods in interfaces?
Default methods provide implementations in interfaces, and static methods belong to the interface itself.
40. What is a daemon thread?
A daemon thread is a low-priority background thread that runs to support other threads.
41. What is a thread pool?
A thread pool manages a group of reusable worker threads to execute tasks efficiently.
42. What is the difference between Callable and Runnable?
Runnable does not return a result, whereas Callable returns a result and can throw exceptions.
43. What is reflection in Java?
Reflection allows inspecting and manipulating classes, methods, and fields at runtime.
44. What is serialization?
Serialization is the process of converting an object into a byte stream for storage or transmission.
45. What is the transient keyword?
The transient keyword prevents a field from being serialized.
46. What is the volatile keyword?
Volatile ensures that a variable is read directly from main memory, preventing thread caching issues.
47. What is the difference between deep copy and shallow copy?
A shallow copy copies only references, whereas a deep copy duplicates the actual objects.
48. What is an enum in Java?
An enum is a special Java type used to define collections of constants.
49. What is Java 8's Optional class?
Optional is a container object that may or may not contain a non-null value to avoid NullPointerException.
50. What is the difference between fail-fast and fail-safe iterators?
Fail-fast iterators throw ConcurrentModificationException, whereas fail-safe iterators work on a copy of the collection.