1z0-851 Actual Exam Questions

Last updated on Nov. 25, 2024.
Vendor:Oracle
Exam Code:1z0-851
Exam Name:Java SE 6 Programmer Certified Professional
Exam Questions:260
 

Topic 1 - Single Topic

Question #1 Topic 1

Given:
public class Threads2 implements Runnable {
public void run() {
System.out.println("run.");
throw new RuntimeException("Problem");
}
public static void main(String[] args) {
Thread t = new Thread(new Threads2());
t.start();
System.out.println("End of method.");
}
}
Which two can be results? (Choose two.)

  • A. java.lang.RuntimeException: Problem
  • B. run. java.lang.RuntimeException: Problem
  • C. End of method. java.lang.RuntimeException: Problem
  • D. End of method. run. java.lang.RuntimeException: Problem
  • E. run. java.lang.RuntimeException: Problem
Reveal Solution Hide Solution   Discussion  

Correct Answer: DE 🗳️
End of method.
run.
Exception in thread "Thread-0" java.lang.RuntimeException: Problem at Threads2.run(Threads2.java:5) at java.lang.Thread.run(Unknown Source)

Question #2 Topic 1

Which two statements are true? (Choose two.)

  • A. It is possible for more than two threads to deadlock at once.
  • B. The JVM implementation guarantees that multiple threads cannot enter into a deadlocked state.
  • C. Deadlocked threads release once their sleep() method's sleep duration has expired.
  • D. Deadlocking can occur only when the wait(), notify(), and notifyAll() methods are used incorrectly.
  • E. It is possible for a single-threaded application to deadlock if synchronized blocks are used incorrectly.
  • F. If a piece of code is capable of deadlocking, you cannot eliminate the possibility of deadlocking by inserting invocations of Thread.yield().
Reveal Solution Hide Solution   Discussion  

Correct Answer: AF 🗳️

Question #3 Topic 1

Given:
void waitForSignal() {
Object obj = new Object();
synchronized (Thread.currentThread()) {
obj.wait();
obj.notify();
}
}
Which statement is true?

  • A. This code can throw an InterruptedException.
  • B. This code can throw an IllegalMonitorStateException.
  • C. This code can throw a TimeoutException after ten minutes.
  • D. Reversing the order of obj.wait() and obj.notify() might cause this method to complete normally.
  • E. A call to notify() or notifyAll() from another thread might cause this method to complete normally.
  • F. This code does NOT compile unless "obj.wait()" is replaced with "((Thread) obj).wait()".
Reveal Solution Hide Solution   Discussion  

Correct Answer: B 🗳️
Not quite sure about the answer, because first of all this code will not compile:
Threads2.java:15: unreported exception java.lang.InterruptedException; must be caught or declared to be thrown obj.wait();
^
1 error

Question #4 Topic 1

Given:
class PingPong2 {
synchronized void hit(long n) {
for(int i = 1; i < 3; i++)
System.out.print(n + "-" + i + " ");
}
}
public class Tester implements Runnable {
static PingPong2 pp2 = new PingPong2();
public static void main(String[] args) {
new Thread(new Tester()).start();
new Thread(new Tester()).start();
}
public void run() { pp2.hit(Thread.currentThread().getId()); }
}
Which statement is true?

  • A. The output could be 5-1 6-1 6-2 5-2
  • B. The output could be 6-1 6-2 5-1 5-2
  • C. The output could be 6-1 5-2 6-2 5-1
  • D. The output could be 6-1 6-2 5-1 7-1
Reveal Solution Hide Solution   Discussion  

Correct Answer: B 🗳️

Question #5 Topic 1

Given:
public class Threads4 {
public static void main (String[] args) {
new Threads4().go();
}
public void go() {
Runnable r = new Runnable() {
public void run() {
System.out.print("foo");
}
};
Thread t = new Thread(r);
t.start();
t.start();
}
}
What is the result?

  • A. Compilation fails.
  • B. An exception is thrown at runtime.
  • C. The code executes normally and prints "foo".
  • D. The code executes normally, but nothing is printed.
Reveal Solution Hide Solution   Discussion  

Correct Answer: B 🗳️
Exception in thread "main" java.lang.IllegalThreadStateException at java.lang.Thread.start(Unknown Source) at Threads4.go(Threads4.java:14) at Threads4.main(Threads4.java:3) foo

file Viewing page 1 out of 52 pages.
Viewing questions 1-5 out of 260 questions
Next Questions
Browse atleast 50% to increase passing rate cup
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago