Summer Sale Limited Time 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: ecus65

Oracle 1z0-830 - Java SE 21 Developer Professional

Page: 1 / 3
Total 84 questions

Which three of the following are correct about the Java module system?

A.

Code in an explicitly named module can access types in the unnamed module.

B.

The unnamed module exports all of its packages.

C.

If a package is defined in both a named module and the unnamed module, then the package in the unnamed module is ignored.

D.

We must add a module descriptor to make an application developed using a Java version prior to SE9 run on Java 11.

E.

The unnamed module can only access packages defined in the unnamed module.

F.

If a request is made to load a type whose package is not defined in any known module, then the module system will attempt to load it from the classpath.

Given a properties file on the classpath named Person.properties with the content:

ini

name=James

And:

java

public class Person extends ListResourceBundle {

protected Object[][] getContents() {

return new Object[][]{

{"name", "Jeanne"}

};

}

}

And:

java

public class Test {

public static void main(String[] args) {

ResourceBundle bundle = ResourceBundle.getBundle("Person");

String name = bundle.getString("name");

System.out.println(name);

}

}

What is the given program's output?

A.

MissingResourceException

B.

Compilation fails

C.

James

D.

JeanneJames

E.

JamesJeanne

F.

Jeanne

Given:

java

int post = 5;

int pre = 5;

int postResult = post++ + 10;

int preResult = ++pre + 10;

System.out.println("postResult: " + postResult +

", preResult: " + preResult +

", Final value of post: " + post +

", Final value of pre: " + pre);

What is printed?

A.

postResult: 15, preResult: 16, Final value of post: 6, Final value of pre: 6

B.

postResult: 16, preResult: 16, Final value of post: 6, Final value of pre: 6

C.

postResult: 15, preResult: 16, Final value of post: 5, Final value of pre: 6

D.

postResult: 16, preResult: 15, Final value of post: 6, Final value of pre: 5

Given:

java

StringBuffer us = new StringBuffer("US");

StringBuffer uk = new StringBuffer("UK");

Stream stream = Stream.of(us, uk);

String output = stream.collect(Collectors.joining("-", "=", ""));

System.out.println(output);

What is the given code fragment's output?

A.

US-UK

B.

An exception is thrown.

C.

-US=UK

D.

=US-UK

E.

Compilation fails.

F.

US=UK

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?

A.

Compilation fails

B.

IOException

C.

RuntimeException

D.

ArithmeticException

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?

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);

Which of the following statements oflocal variables declared with varareinvalid?(Choose 4)

A.

var a = 1;(Valid: var correctly infers int)

B.

var b = 2, c = 3.0;

C.

var d[] = new int[4];

D.

var e;

E.

var f = { 6 };

F.

var h = (g = 7);

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?

A.

truetruefalse

B.

falsetruetrue

C.

truefalsetrue

D.

truetruetrue

E.

Compilation fails

Given:

java

Optional optionalName = Optional.ofNullable(null);

String bread = optionalName.orElse("Baguette");

System.out.print("bread:" + bread);

String dish = optionalName.orElseGet(() -> "Frog legs");

System.out.print(", dish:" + dish);

try {

String cheese = optionalName.orElseThrow(() -> new Exception());

System.out.println(", cheese:" + cheese);

} catch (Exception exc) {

System.out.println(", no cheese.");

}

What is printed?

A.

bread:Baguette, dish:Frog legs, cheese.

B.

bread:Baguette, dish:Frog legs, no cheese.

C.

bread:bread, dish:dish, cheese.

D.

Compilation fails.

Given:

java

Object myVar = 0;

String print = switch (myVar) {

case int i -> "integer";

case long l -> "long";

case String s -> "string";

default -> "";

};

System.out.println(print);

What is printed?

A.

integer

B.

long

C.

string

D.

nothing

E.

It throws an exception at runtime.

F.

Compilation fails.