Certbus > Oracle > Oracle Database > 1Z0-809 > 1Z0-809 Online Practice Questions and Answers

1Z0-809 Online Practice Questions and Answers

Questions 4

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?

A. The program prints 1 2 3 and the order is unpredictable.

B. The program prints 1 2 3.

C. The program prints 1 1 1.

D. A compilation error occurs.

Browse 207 Q&As
Questions 5

Given the code fragment:

List listVal = Arrays.asList("Joe", "Paul", "Alice", "Tom");

System.out.println (

// line n1

);

Which code fragment, when inserted at line n1, enables the code to print the count of string elements

whose length is greater than three?

A. listVal.stream().filter(x -> x.length()>3).count()

B. listVal.stream().map(x -> x.length()>3).count()

C. listVal.stream().peek(x -> x.length()>3).count().get()

D. listVal.stream().filter(x -> x.length()>3).mapToInt(x -> x).count()

Browse 207 Q&As
Questions 6

Given:

public class Customer {

private String fName;

private String lName;

private static int count;

public customer (String first, String last) {fName = first, lName = last;

++count;}

static { count = 0; }

public static int getCount() {return count; }

}

public class App {

public static void main (String [] args) {

Customer c1 = new Customer("Larry", "Smith");

Customer c2 = new Customer("Pedro", "Gonzales");

Customer c3 = new Customer("Penny", "Jones");

Customer c4 = new Customer("Lars", "Svenson");

c4 = null;

c3 = c2;

System.out.println (Customer.getCount());

}

}

What is the result?

A. 0

B. 2

C. 3

D. 4

E. 5

Browse 207 Q&As
Questions 7

Which two code blocks correctly initialize a Locale variable? (Choose two.)

A. Locale loc1 = "UK";

B. Locale loc2 = Locale.getInstance("ru");

C. Locale loc3 = Locale.getLocaleFactory("RU");

D. Locale loc4 = Locale.UK;

E. Locale loc5 = new Locale ("ru", "RU");

Browse 207 Q&As
Questions 8

Given:

class RateOfInterest {

public static void main (String[] args) {

int rateOfInterest = 0;

String accountType = "LOAN";

switch (accountType) {

case "RD";

rateOfInterest = 5;

break;

case "FD";

rateOfInterest = 10;

break;

default: assert false: "No interest for this account"; //line n1 } System.out.println ("Rate of interest:" + rateOfInterest); } }

and the command:

java -ea RateOfInterest

What is the result?

A. Rate of interest: 0

B. An AssertionError is thrown.

C. No interest for this account

D. A compilation error occurs at line n1.

Browse 207 Q&As
Questions 9

Given the code fragment:

class CallerThread implements Callable {

String str;

public CallerThread(String s) {this.str=s;}

public String call() throws Exception {

return str.concat("Call");

}

}

and

public static void main (String[] args) throws InterruptedException, ExecutionException

{

ExecutorService es = Executors.newFixedThreadPool(4); //line n1

Future f1 = es.submit (newCallerThread("Call"));

String str = f1.get().toString();

System.out.println(str);

}

Which statement is true?

A. The program prints Call Call and terminates.

B. The program prints Call Call and does not terminate.

C. A compilation error occurs at line n1.

D. An ExecutionException is thrown at run time.

Browse 207 Q&As
Questions 10

Given the code fragment:

What is the result?

A. A compilation error occurs at line n1.

B. Logged out at: 2015-01-12T21:58:19.880Z

C. Can't logout

D. Logged out at: 2015-01-12T21:58:00Z

Browse 207 Q&As
Questions 11

Given the code fragment:

What is the result?

A. A compilation error occurs at line n1.

B. Checking...

C. Checking... Checking...

D. A compilation error occurs at line n2.

Browse 207 Q&As
Questions 12

Assume customers.txt is accessible and contains multiple lines.

Which code fragment prints the contents of the customers.txt file?

A. Stream stream = Files.find (Paths.get ("customers.txt")); stream.forEach((String c) -> System.out.println(c));

B. Stream stream = Files.find (Paths.get ("customers.txt")); stream.forEach( c) -> System.out.println(c));

C. Stream stream = Files.list (Paths.get ("customers.txt")); stream.forEach( c) -> System.out.println(c));

D. Stream lines = Files.lines (Paths.get ("customers.txt")); lines.forEach( c) -> System.out.println(c));

Browse 207 Q&As
Questions 13

Given:

and the code fragment:

What is the result?

A. An exception is thrown at line n2.

B. 100

C. A compilation error occurs because the try block is declared without a catch or finally block.

D. A compilation error occurs at line n1.

Browse 207 Q&As
Questions 14

Given the Greetings.properties file, containing:

and given:

What is the result?

A. Compilation fails.

B. GOODBY_MSG

C. Hello, everyone!

D. Goodbye everyone!

E. HELLO_MSG

Browse 207 Q&As
Questions 15

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 method.

E. Threads cannot acquire intrinsic locks on classes.

Browse 207 Q&As
Questions 16

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;

}

public String getCourse() {return course;}

public String getName() {return name;}

public String getCity() {return city;}

and the code fragment:

List 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?

A. A compilation error occurs.

B. Java EE Java ME

C. [Java EE: Helen:Houston] [Java ME: Jessy:Chicago, Java ME: Mark:Chicago]

D. [Java ME: Jessy:Chicago, Java ME: Mark:Chicago] [Java EE: Helen:Houston]

Browse 207 Q&As
Questions 17

Given:

public class Counter {

public static void main (String[ ] args) {

int a = 10;

int b = -1;

assert (b >=1) : "Invalid Denominator";

int = a / b;

System.out.println (c);

}

}

What is the result of running the code with the 璬a option?

A. -10

B. 0

C. An AssertionError is thrown.

D. A compilation error occurs.

Browse 207 Q&As
Questions 18

Given the code fragment:

Path path1 = Paths.get("/app/./sys/");

Path res1 = path1.resolve("log");

Path path2 = Paths.get("/server/exe/");

Path res1 = path2.resolve("/readme/");

System.out.println(res1);

System.out.println(res2);

What is the result?

A. /app/sys/log /readme/server/exe

B. /app/log/sys /server/exe/readme

C. /app/./sys/log /readme

D. /app/./sys/log /server/exe/readme

Browse 207 Q&As
Exam Code: 1Z0-809
Exam Name: Java SE 8 Programmer II
Last Update: Mar 08, 2024
Questions: 207 Q&As

PDF

$45.99

VCE

$49.99

PDF + VCE

$59.99