Which two statements are true about synchronization and locks? (Choose two.)
A. A thread automatically acquires the intrinsic lock on a synchronized statement when executed.
B. The intrinsic lock will be retained by a thread if return from a synchronized method is caused by an uncaught exception.
C. A thread exclusively owns the intrinsic lock of an object between the time it acquires the lock and the time it releases it.
D. A thread automatically acquires the intrinsic lock on a synchronized method's object when entering that
E. Threads cannot acquire intrinsic locks on classes.
Answer: C D
Every object has an intrinsic lock associated with it. By convention, a thread that needs exclusive and consistent access to an object's fields has to acquire the object's intrinsic lock before accessing them, and then release the intrinsic lock when it's done with them. A thread is said to own the intrinsic lock between the time it has acquired the lock and released the lock. As long as a thread owns an intrinsic lock, no other thread can acquire the same lock. The other thread will block when it attempts to acquire the lock.
When a thread invokes a synchronized method, it automatically acquires the intrinsic lock for that method's object and releases it when the method returns. The lock release occurs even if the return was caused by an uncaught exception.

Which two are elements of a singleton class? (Choose two.)
A. a transient reference to point to the single instance
B. a public method to instantiate the single instance
C. a public static method to return a copy of the singleton reference
D. a private constructor to the class
E. a public reference to point to the single instance
Answer: C D

What is true about the java.sql.Statement interface?
A. It provides a session with the database.
B. It is used to get an instance of a Connection object by using JDBC drivers.
C. It provides a cursor to fetch the resulting data.
D. It provides a class for executing SQL statements and returning the results.
Answer: D
A Statement object is used for executing a static SQL statement and obtaining the results produced by it.

public interface P { public void method1(); }
public interface Q extends P { public void method1(); }
public interface R extends P { public void method2(); }
public interface S { public default void method() { } }
public interface Q extends P { public void method1(); }
public interface U { public void methodi () ; public abstract void method2 ();}
Which two interfaces can you use to create lambda expressions? (Choose two.)
A. T
B. R
C. P
D. S
E. Q
F. U
Answer: C E
P pp = () -> System.out.println("P");
Q qq = () -> System.out.println(“Q");

Which two statements are true about the Fork/Join Framework? (Choose two.)
A. The RecursiveTask subclass is used when a task does not need to return a result.
B. The Fork/Join framework can help you take advantage of multicore hardware.
C. The Fork/Join framework implements a work-stealing algorithm.
D. The Fork/Join solution when run on multicore hardware always performs faster than standard sequential solution.
Answer: A C
The fork/join framework is an implementation of the ExecutorService interface that helps you take advantage of multiple processors. It is designed for work that can be broken into smaller pieces recursively. The goal is to use all the available processing power to enhance the performance of your application.
As with any ExecutorService implementation, the fork/join framework distributes tasks to worker threads in a thread pool. The fork/join framework is distinct because it uses a work-stealing algorithm. Worker threads that run out of things to do can steal tasks from other threads that are still busy.

Which two methods from the interface perform a reduction operation? (Choose two.)
A. count ()
B. collect ()
C. distinct ()
D. peek ()
E. filter ()
Answer: A B
reduce(), collect(), sum(), max(), count()

public interface LengthValidator {
public boolean checkLength(String str);
public class Txt {
public static void main(String[] args)
boolean res = new LengthValidator()
public boolean checkLength(String str)
return str.length() > 5 && str.length() < 10;
Which interface from the java.util.function package should you use to refactor the class Txt?
A. Consumer
B. Predicate
C. Supplier
D. Function
Answer: B
public static Predicate hasLengthOf = new Predicate() {
public boolean test(String str)
return str.length() > 5 && str.length() < 10;


dragonH iT邦超人 6 級 ‧ 2019-05-11 21:59:45 檢舉 不客氣