Java Unit3 Unit4 QA
Java Unit3 Unit4 QA
1. What Is a Functional Interface? What Are the Rules of Defining a Functional Interface?
A functional interface is an interface that contains exactly one abstract method. It can have multiple
2. Describe Some of the Functional Interfaces in the Standard Library. What Is a Lambda
Lambda Expression is a concise way to implement functional interfaces using syntax (parameters)
-> { body }.
Default method: Method in an interface with a default implementation using the `default` keyword.
Static method: Method in an interface or class that belongs to the interface/class, not an instance.
Difference: Collections store data; Streams process data using functional operations like map, filter,
reduce.
6. Is it possible to define our own Functional Interface? What is @FunctionalInterface? What are the
Yes. @FunctionalInterface ensures only one abstract method is present. Rules: one abstract
Use Stream API for functional-style data processing. Benefits: concise, readable, efficient data
manipulation.
Base64 encoding converts binary data into an ASCII string format using java.util.Base64 class.
Java Type Annotations provide metadata for types. Repeating Annotations allow the same
At the top is Collection interface. Subinterfaces: List, Set, Queue. Implementations include ArrayList,
Iterator allows sequential access of elements in a collection and supports element removal.
3. Differentiate between the Collection interface and the Collections class in Java.
Collection is an interface; Collections is a utility class with static methods like sort(), reverse().
5. What is the role of the Set interface in Java, and how does it differ from other collection types?
Set doesn't allow duplicate elements. Unlike List, it doesn't maintain insertion order (except
LinkedHashSet).
HashSet: unordered.
7. How does the TreeMap class differ from HashMap and LinkedHashMap in Java?
HashMap: unordered.
8. What is the Comparable interface, and how is it used for sorting objects in Java?
each?
environments.
11. Describe the Properties class in Java and its common use cases.
Used for config files, storing settings in .properties files, supports load() and store().
13. Write a Java program that demonstrates sorting an ArrayList of custom objects using the
Comparable interface.
int marks;
14. Write a Java program to demonstrate basic operations (addition, removal, and iteration) on a
set.add("A");
set.remove("A");
15. Implement Java program to create a TreeSet of integers and perform operations like addition,
ts.add(3);
ts.remove(3);
ts.forEach(System.out::println);