Java Online Screening TestBy Collab Team Contributor / February 8, 2025 Java Online Screening Test 1 / 20 Which of the following is true about volatile in Java? It ensures atomicity. It ensures visibility but not atomicity. It replaces synchronized blocks. It locks the variable. 2 / 20 What will happen if a thread calls the wait() method inside a synchronized block? It will continue execution. It will go to the ready state. It will release the lock and enter the waiting state. It will throw an exception. 3 / 20 What will happen if join() is called on a thread? Both threads terminate immediately. The joined thread waits for the calling thread. The calling thread waits for the joined thread to finish. The program exits. 4 / 20 What will Optional.ofNullable(null).orElse("Default") return? null Compilation error NoSuchElementException d "Default" 5 / 20 Which method is used to schedule a task for execution in ScheduledExecutorService? run() execute() schedule() start() 6 / 20 What is the default capacity of an ArrayList when initialized with an empty constructor? 16 8 10 5 7 / 20 Which functional interface does the forEach() method accept? Predicate Function Supplier Consumer 8 / 20 Which class in Java is immutable by design? String ArrayList StringBuilder HashMap 9 / 20 Which Java class is designed for thread-safe counter updates? AtomicInteger ThreadLocal Integer Semaphore 10 / 20 Which of the following is true about Java garbage collection? It can be explicitly controlled. It automatically removes unreachable objects. It guarantees that all unused objects are removed. Developers must manually call the garbage collector. 11 / 20 Which method of ConcurrentHashMap is atomic? get() remove() put() computeIfAbsent() 12 / 20 Which Java feature ensures that an object is not modified once it is created? Serialization Immutability Polymorphism Encapsulation 13 / 20 Which functional interface represents an operation that takes one argument and returns a result? Supplier Function Runnable Consumer 14 / 20 Which collection class allows concurrent modification by multiple threads? HashSet CopyOnWriteArrayList ArrayList LinkedList 15 / 20 What does the filter() method in Java Streams do? Converts elements to another type Modifies each element in the stream Filters elements based on a predicate Sorts elements in the stream 16 / 20 Which of the following is not a valid access modifier in Java? internal protected private public 17 / 20 Which interface provides a method to retrieve elements sequentially from a collection? HashMap Iterable Enumeration Comparator 18 / 20 Which stream operation is terminal? map() collect() flatMap() filter() 19 / 20 Which lock mechanism in Java provides explicit control over locking? volatile keyword ReentrantLock AtomicBoolean synchronized block 20 / 20 Which Java collection class does not allow duplicate keys but allows duplicate values? TreeMap HashSet HashMap LinkedList Your score isThe average score is 56% 0% Restart quiz