21. What is the purpose of the ‘Callable’ and ‘Future’ interfaces in Java’s concurrency framework?
- ‘Callable‘ is used to define a task that can be executed asynchronously, and ‘Future’ is used to retrieve the result of a ‘Callable’ task when it’s complete.
22. Explain the concept of Java NIO (New I/O) and its advantages.
- Java NIO is a non-blocking I/O system that provides better performance and scalability for network and file I/O compared to traditional I/O.
23. What is the purpose of the ‘Atomic’ classes in Java, such as ‘AtomicInteger’?
- ‘Atomic’ classes provide atomic operations (e.g., increment, compare-and-swap) without the need for external synchronization, making them suitable for multi-threaded environments.
24. What are annotations like ‘@Override’ and ‘@Deprecated’ used for in Java?
- Annotations provide metadata about code elements. ‘@Override’ indicates that a method is intended to override a superclass method, and ‘@Deprecated’ marks elements as obsolete.
25. Explain the concept of ‘JavaFX’ and its use in Java applications.
- JavaFX is a framework for creating graphical user interfaces in Java. It provides a rich set of tools and libraries for building interactive desktop and web applications.
26. What is the ‘ClassLoader’ hierarchy in Java, and how does class loading work?
- Java uses a hierarchical ClassLoader system to load classes. Classes are loaded in a parent-child relationship, with the Bootstrap ClassLoader at the top.
27. What is the ‘ConcurrentHashMap’ class in Java, and how is it different from ‘HashMap’?
- ‘ConcurrentHashMap’ is a thread-safe version of ‘HashMap’ that allows multiple threads to read and write without blocking, improving concurrency.
28. Explain the purpose of the ‘java.util.concurrent’ package in Java.
- The ‘java.util.concurrent’ package provides a framework for concurrent programming, including classes for thread management, synchronization, and concurrent data structures.
29. What is a ‘ClassLoader’ in Java, and how does it relate to class loading?
- A ClassLoader is responsible for loading classes into the Java Virtual Machine. It searches for classes in the classpath and loads them when needed.
30. What is the ‘Annotation Processing Tool (APT)’ in Java, and how is it used?
- APT is a tool used to process annotations and generate code during compilation. It’s often used for code generation and validation.
31. What is the ‘PermGen’ space in Java, and why was it replaced with ‘Metaspace’?
- ‘PermGen’ was a fixed-size memory area to store class metadata and String pool. It was replaced with ‘Metaspace’ in Java 8 to allow for dynamic memory allocation and avoid PermGen-related issues.
32. Explain the ‘Lambda Expression’ introduced in Java 8 and its use in functional programming.
- Lambda expressions allow you to define functions in a concise way. They are often used with functional interfaces to enable functional programming in Java.
33. What is the purpose of the ‘spliterator’ in Java, and how is it used in collections?
- A ‘spliterator’ is used to traverse and partition elements in a collection for parallel processing. It’s often used in the Java Stream API.
34. What is the ‘assertThrows’ method in JUnit 5, and how is it used for testing exceptions?
- ‘assertThrows’ is a method in JUnit 5 that is used to test if a specific exception is thrown when a method is called during testing.
35. Explain the concept of ‘Optional’ in Java and how it is used to handle null values.
- ‘Optional’ is a container that may or may not contain a non-null value. It helps avoid null pointer exceptions and makes it clear when a value can be absent.
36. What is the purpose of ‘Java Mission Control’ (JMC) and ‘Java Flight Recorder’ (JFR) in Java applications?
- JMC and JFR are tools for monitoring, profiling, and troubleshooting Java applications, providing insights into application performance and resource usage.
37. Explain the concept of ‘Java Message Service (JMS)’ and its role in asynchronous messaging.
- JMS is an API for sending and receiving messages between distributed applications, providing a reliable and asynchronous communication mechanism.
38. What is the ‘FunctionalInterface’ annotation in Java, and why is it used?
- ‘FunctionalInterface’ is an annotation used to indicate that an interface has a single abstract method, making it eligible for use with lambda expressions and method references.
39. Explain the purpose of ‘Reference’ classes in Java, such as ‘SoftReference’ and ‘WeakReference’.
- ‘Reference’ classes provide a way to interact with the garbage collector and manage the lifecycle of objects. ‘SoftReference’ and ‘WeakReference’ allow objects to be collected when memory is low or when they have no strong references.
40. What are ‘Java Agents,’ and how can they be used to enhance application behavior?
- Java Agents are used to dynamically modify the behavior of running Java applications, typically for purposes like monitoring, profiling, or code injection.