Free Oracle 1Z0-829 Exam Braindumps (page: 2)

Given the code fragments:



Which is true?

  1. The program prints t1 : 1: t2 : 1: t1 : t2 : 2 : in random order.
  2. The program prints t1 : 1 : t2: 1 : t1 : 2 : t2: 2:
  3. The program prints t1 : 1: t2 : 1: t1 : 1 : t2 : 1 : indefinitely
  4. The program prints an exception

Answer(s): B

Explanation:

The code creates two threads, t1 and t2, and starts them. The threads will print their names and the value of the Atomic Integer object, x, which is initially set to 1. The threads will then increment the value of x and print their names and the new value of x. Since the threads are started at the same time, the output will be in random order. However, the final output will always be t1 : 1 : t2: 1 : t1 : 2 : t2: 2:


Reference:

AtomicInteger (Java SE 17 & JDK 17) - Oracle



Which statement is true?

  1. IllegalStateException is thrown if a thread in waiting state is moved back to runnable.
  2. thread in waiting state consumes CPU cycles.
  3. A thread in waiting state must handle InterrupedException.
  4. After the timed wait expires, the waited thread moves to the terminated state.

Answer(s): C

Explanation:

A thread in waiting state is waiting for another thread to perform a particular action, such as calling notify() or notifyAll() on a shared object, or terminating a joined thread. A thread in waiting state can be interrupted by another thread, which will cause the waiting thread to throw an InterruptedException and return to the runnable state. Therefore, a thread in waiting state must handle InterruptedException, either by catching it or declaring it in the throws clause.


Reference:

Thread.State (Java SE 17 & JDK 17), [Thread (Java SE 17 & JDK 17)]



Given the code fragment:



Which code fragment invokes all callable objects in the workers set?









Answer(s): C

Explanation:

The code fragment in Option C invokes all callable objects in the workers set by using the ExecutorService's invokeAll() method. This method takes a collection of Callable objects and returns a list of Future objects representing the results of the tasks. The other options are incorrect because they either use the wrong method (invokeAny() or submit()) or have syntax errors (missing parentheses or semicolons).


Reference:

AbstractExecutorService (Java SE 17 & JDK 17) - Oracle



Given the code fragment:



What is the result?

  1. 81111
  2. 8109
  3. 777
  4. 71010
  5. 888
  6. 7107

Answer(s): B

Explanation:

The code fragment is creating a string variable "a" with the value "Hello! Java". Then, it is printing the index of "Java" in "a". Next, it is replacing "Hello!" with "Welcome!" in "a". Then, it is printing the index of "Java" in "a". Finally, it is creating a new StringBuilder object "b" with the value of "a" and printing the index of "Java" in "b". The output will be 8109 because the index of "Java" in "a" is 8, the index of "Java" in "a" after replacing "Hello!" with "Welcome!" is 10, and the index of "Java" in "b" is 9.


Reference:

Oracle Java SE 17 Developer source and documents: [String (Java SE 17 & JDK 17)], [StringBuilder (Java SE 17 & JDK 17)]






Post your Comments and Discuss Oracle 1Z0-829 exam prep with other Community members:

1Z0-829 Exam Discussions & Posts