Free Oracle 1Z0-809 Exam Questions (page: 7)

Given the code fragments:
class MyThread implements Runnable {
private static AtomicInteger count = new AtomicInteger (0);
public void run () {
int x = count.incrementAndGet();
System.out.print (x+” “);
}
}

and

Thread thread1 = new Thread(new MyThread());
Thread thread2 = new Thread(new MyThread());
Thread thread3 = new Thread(new MyThread());

Thread [] ta = {thread1, thread2, thread3};
for (int x= 0; x < 3; x++) {
ta[x].start();
}

Which statement is true?

  1. The program prints 1 2 3 and the order is unpredictable.
  2. The program prints 1 2 3.
  3. The program prints 1 1 1.
  4. A compilation error occurs.

Answer(s): A



Given the code fragment:
public static void main (String [ ] args) throws IOException {
BufferedReader br = new BufferedReader (new InputStremReader (System.in));
System.out.print (“Enter GDP: “);
//line 1
}

Which code fragment, when inserted at line 1, enables the code to read the GDP from the user?

  1. int GDP = Integer.parseInt (br.readline());
  2. int GDP = br.read();
  3. int GDP = br.nextInt();
  4. int GDP = Integer.parseInt (br.next());

Answer(s): A



Given the code fragment:
Path source = Paths.get (“/data/december/log.txt”);
Path destination = Paths.get(“/data”);
Files.copy (source, destination);

and assuming that the file /data/december/log.txt is accessible and contains:
10-Dec-2014 – Executed successfully

What is the result?

  1. A file with the name log.txt is created in the /data directory and the content of the /data/december/ log.txt file is copied to it.
  2. The program executes successfully and does NOT change the file system.
  3. A FileNotFoundException is thrown at run time.
  4. A FileAlreadyExistsException is thrown at run time.

Answer(s): D



Given:
class Student {
String course, name, city;
public Student (String name, String course, String city) {
this.course = course; this.name = name; this.city = city;
}
public String toString() {
return course + “:” + name + “:” + city;
}

and the code fragment:

List<Student> stds = Arrays.asList(
new Student (“Jessy”, “Java ME”, “Chicago”),
new Student (“Helen”, “Java EE”, “Houston”),
new Student (“Mark”, “Java ME”, “Chicago”));
stds.stream()
.collect(Collectors.groupingBy(Student::getCourse))
.forEach(src, res) -> System.out.println(scr));


What is the result?

  1. [Java EE: Helen:Houston]
    [Java ME: Jessy:Chicago, Java ME: Mark:Chicago]
  2. Java EE Java ME
  3. [Java ME: Jessy:Chicago, Java ME: Mark:Chicago] [Java EE: Helen:Houston]
  4. A compilation error occurs.

Answer(s): B



Viewing page 7 of 42



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

1Z0-809 Exam Discussions & Posts