Which interface in the Java Collections Framework represents a group of objects where duplicates are not allowed?
List
Queue
Map
Set
What will the following code snippet print?
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5); long count = numbers.stream().filter(n -> n % 2 == 0).map(n -> n * 2).count(); System.out.println(count);
10
2
4
5
What happens when a generic class is instantiated with a primitive type in Java?
The primitive type is autoboxed to its wrapper class.
It works as expected.
A compile-time error occurs.
A runtime exception is thrown.
How can you access the value of an annotation's element at runtime?
By using the getAnnotation() method
getAnnotation()
By casting the annotated element to the annotation type
By accessing the annotation element directly as a field of the annotated element
By using the getDeclaredAnnotation() method
getDeclaredAnnotation()
Which Java method would you use to find the index of the first occurrence of a specific substring within a string?
length()
substring()
charAt()
indexOf()
In Java's concurrency model, what is the primary purpose of a 'wait()' call on an object?
To release the object's lock and put the thread in a waiting state
To signal other waiting threads to resume execution
To check if the object's lock is available
To forcefully acquire the object's lock
What is the purpose of defining a custom annotation in Java?
To define new data types
To control access modifiers for classes and methods
To create new keywords in the Java language
To attach metadata to classes, methods, or fields
What happens when a Stream encounters an exception during execution?
The exception is caught and wrapped in a RuntimeException
The stream processing stops, and the exception is thrown
The stream processing pauses, and the user is prompted to handle the exception
The exception is ignored, and the stream continues processing
What does the File.createNewFile() method do if a file with the same name already exists in the specified location?
File.createNewFile()
It appends a number to the file name to create a unique file.
It throws a FileNotFoundException.
FileNotFoundException
It overwrites the existing file with an empty file.
It returns false without creating a new file.
false
Which class in the java.time package represents a date without a time component?
java.time
ZonedDateTime
LocalDateTime
LocalDate
Instant