Pass the Oracle Java SE 1z0-830 Questions and answers with CertsForce

Viewing page 2 out of 3 pages
Viewing questions 11-20 out of questions
Questions # 11:

Given:

java

ExecutorService service = Executors.newFixedThreadPool(2);

Runnable task = () -> System.out.println("Task is complete");

service.submit(task);

service.shutdown();

service.submit(task);

What happens when executing the given code fragment?

Options:

A.

It prints "Task is complete" once and throws an exception.


B.

It prints "Task is complete" twice and throws an exception.


C.

It exits normally without printing anything to the console.


D.

It prints "Task is complete" twice, then exits normally.


E.

It prints "Task is complete" once, then exits normally.


Expert Solution
Questions # 12:

How would you create a ConcurrentHashMap configured to allow a maximum of 10 concurrent writer threads and an initial capacity of 42?

Which of the following options meets this requirement?

Options:

A.

var concurrentHashMap = new ConcurrentHashMap(42);


B.

None of the suggestions.


C.

var concurrentHashMap = new ConcurrentHashMap();


D.

var concurrentHashMap = new ConcurrentHashMap(42, 10);


E.

var concurrentHashMap = new ConcurrentHashMap(42, 0.88f, 10);


Expert Solution
Questions # 13:

Given:

java

public class Test {

public static void main(String[] args) throws IOException {

Path p1 = Path.of("f1.txt");

Path p2 = Path.of("f2.txt");

Files.move(p1, p2);

Files.delete(p1);

}

}

In which case does the given program throw an exception?

Options:

A.

Neither files f1.txt nor f2.txt exist


B.

Both files f1.txt and f2.txt exist


C.

An exception is always thrown


D.

File f2.txt exists while file f1.txt doesn't


E.

File f1.txt exists while file f2.txt doesn't


Expert Solution
Questions # 14:

Given:

java

var frenchCities = new TreeSet();

frenchCities.add("Paris");

frenchCities.add("Marseille");

frenchCities.add("Lyon");

frenchCities.add("Lille");

frenchCities.add("Toulouse");

System.out.println(frenchCities.headSet("Marseille"));

What will be printed?

Options:

A.

[Paris]


B.

[Paris, Toulouse]


C.

[Lille, Lyon]


D.

Compilation fails


E.

[Lyon, Lille, Toulouse]


Expert Solution
Questions # 15:

Given:

java

public static void main(String[] args) {

try {

throw new IOException();

} catch (IOException e) {

throw new RuntimeException();

} finally {

throw new ArithmeticException();

}

}

What is the output?

Options:

A.

Compilation fails


B.

IOException


C.

RuntimeException


D.

ArithmeticException


Expert Solution
Questions # 16:

Given:

java

public class ExceptionPropagation {

public static void main(String[] args) {

try {

thrower();

System.out.print("Dom Pérignon, ");

} catch (Exception e) {

System.out.print("Chablis, ");

} finally {

System.out.print("Saint-Émilion");

}

}

static int thrower() {

try {

int i = 0;

return i / i;

} catch (NumberFormatException e) {

System.out.print("Rosé");

return -1;

} finally {

System.out.print("Beaujolais Nouveau, ");

}

}

}

What is printed?

Options:

A.

Saint-Émilion


B.

Beaujolais Nouveau, Chablis, Saint-Émilion


C.

Beaujolais Nouveau, Chablis, Dom Pérignon, Saint-Émilion


D.

Rosé


Expert Solution
Questions # 17:

Given:

java

List integers = List.of(0, 1, 2);

integers.stream()

.peek(System.out::print)

.limit(2)

.forEach(i -> {});

What is the output of the given code fragment?

Options:

A.

Compilation fails


B.

An exception is thrown


C.

01


D.

012


E.

Nothing


Expert Solution
Questions # 18:

Given:

java

System.out.print(Boolean.logicalAnd(1 == 1, 2 < 1));

System.out.print(Boolean.logicalOr(1 == 1, 2 < 1));

System.out.print(Boolean.logicalXor(1 == 1, 2 < 1));

What is printed?

Options:

A.

truetruefalse


B.

falsetruetrue


C.

truefalsetrue


D.

truetruetrue


E.

Compilation fails


Expert Solution
Questions # 19:

Given:

java

Runnable task1 = () -> System.out.println("Executing Task-1");

Callable task2 = () -> {

System.out.println("Executing Task-2");

return "Task-2 Finish.";

};

ExecutorService execService = Executors.newCachedThreadPool();

// INSERT CODE HERE

execService.awaitTermination(3, TimeUnit.SECONDS);

execService.shutdownNow();

Which of the following statements, inserted in the code above, printsboth:

"Executing Task-2" and "Executing Task-1"?

Options:

A.

execService.call(task1);


B.

execService.call(task2);


C.

execService.execute(task1);


D.

execService.execute(task2);


E.

execService.run(task1);


F.

execService.run(task2);


G.

execService.submit(task1);


Expert Solution
Questions # 20:

Given:

java

CopyOnWriteArrayList list = new CopyOnWriteArrayList<>();

list.add("A");

list.add("B");

list.add("C");

// Writing in one thread

new Thread(() -> {

list.add("D");

System.out.println("Element added: D");

}).start();

// Reading in another thread

new Thread(() -> {

for (String element : list) {

System.out.println("Read element: " + element);

}

}).start();

What is printed?

Options:

A.

It prints all elements, including changes made during iteration.


B.

It prints all elements, but changes made during iteration may not be visible.


C.

It throws an exception.


D.

Compilation fails.


Expert Solution
Viewing page 2 out of 3 pages
Viewing questions 11-20 out of questions