Exit demo 1Z0-830 Java SE 21 Developer Professional PDF format · free preview

Oracle 1Z0-830 - Questions & Answers

Free preview · every answer includes a full explanation

Product page: https://prepkeys.com/1z0-830.html

Question 1
Single choice

Which of the following isn't a correct way to write a string to a file?

A.

Path path = Paths.get("file.txt");
byte[] strBytes = "Hello".getBytes();
Files.write(path, strBytes);

B.

try (BufferedWriter writer = new BufferedWriter("file.txt")) { writer.write("Hello");
}

C.

java
try (FileOutputStream outputStream = new FileOutputStream("file.txt")) { byte[] strBytes =
"Hello".getBytes();
outputStream.write(strBytes);
}

D.

try (PrintWriter printWriter = new PrintWriter("file.txt")) { printWriter.printf("Hello %s", "James");
}

E.

None of the suggestions

F.

try (FileWriter writer = new FileWriter("file.txt")) {
writer.write("Hello");
}

Question 2
Single choice

Given:

java

Integer frenchRevolution = 1789;

Object o1 = new String("1789");

Object o2 = frenchRevolution;

frenchRevolution = null;

Object o3 = o2.toString();

System.out.println(o1.equals(o3));

What is printed?

A.

true

B.

false

C.

A NullPointerException is thrown.

D.

A ClassCastException is thrown.

E.

Compilation fails.

Question 3
Single choice

Given:

java

public class ExceptionPropagation {

public static void main(String[] args) {

try {

thrower();

}
catch (Exception e) {

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

}
finally {

}

}

static int thrower() {

try {

int i = 0;

return i / i;

}
catch (NumberFormatExceptione) {

return -1;

}
finally {

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

}

}

}

What is printed?

A.

Saint-Emilion

B.

Beaujolais Nouveau, Chablis, Saint-Emilion

C.

Beaujolais Nouveau, Chablis, Dom Pérignon, Saint-Emilion

D.

Rose

Question 4
Single choice

Given:

java

try (FileOutputStream fos = new FileOutputStream("t.tmp");

ObjectOutputStream oos = new ObjectOutputStream(fos)) {

fos.write("Today");

fos.writeObject("Today");

oos.write("Today");

oos.writeObject("Today");

}
catch (Exception ex) {

// handle exception

}

Which statement compiles?

A.

fos.write("Today");

B.

fos.writeObject("Today");

C.

oos.write("Today");

D.

oos.writeObject("Today");

Question 5
Single choice

Given:

java

List<String> abc = List.of("a", "b", "c");

abc.stream()

.forEach(x -> {

x = x.toUpperCase();

});

abc.stream()

.forEach(System.out::print);

What is the output?

A.

abc

B.

An exception is thrown.

C.

Compilation fails.

D.

ABC

Question 6
Single choice

Which StringBuilder variable fails to compile?

java

public class StringBuilderInstantiations {

public static void main(String[] args) {

var stringBuilder1 = new StringBuilder();

var stringBuilder2 = new StringBuilder(10);

var stringBuilder3 = new StringBuilder("Java");

var stringBuilder4 = new StringBuilder(new char[]{'J', 'a', 'v', 'a'});

}

}

A.

None of them

B.

stringBuilder4

C.

stringBuilder1

D.

stringBuilder3

E.

stringBuilder2

Question 7
Single choice

Given:

java

List<String> l1 = new ArrayList<>(List.of("a", "b"));

List<String> l2 = new ArrayList<>(Collections.singletonList("c"));

Collections.copy(l1, l2);

l2.set(0, "d");

System.out.println(l1);

What is the output of the given code fragment?

A.

[a, b]

B.

[d, b]

C.

[c, b]

D.

An UnsupportedOperationException is thrown

E.

An IndexOutOfBoundsException is thrown

F.

[d]

Question 8
Single choice

Given:

java

public class Test {

static int count;

synchronized Test() {

count++;

}

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

Runnable task = Test::new;

Thread t1 = new Thread(task);

Thread t2 = new Thread(task);

t1.start();

t2.start();

t1.join();

t2.join();

System.out.println(count);

}

}

What is the given program's output?

A.

It's either 1 or 2

B.

It's either 0 or 1

C.

It's always 2

D.

It's always 1

E.

Compilation fails

Question 9
Multiple choice

Which two of the following aren't the correct ways to create a Stream?

A.

Stream stream = Stream.of("a");

B.

Stream stream = Stream.ofNullable("a");

C.

Stream stream = Stream.generate(() -> "a");

D.

Stream stream = Stream.of();

E.

Stream stream = new Stream();

F.

Stream<String> stream = Stream.builder().add("a").build();

G.

Stream stream = Stream.empty();

Question 10
Single choice

Given:

java

var now = LocalDate.now();

var format1 = new DateTimeFormatter(ISO_WEEK_DATE);

var format2 = DateTimeFormatter.ISO_WEEK_DATE;

var format3 = new DateFormat(WEEK_OF_YEAR_FIELD);

var format4 = DateFormat.getDateInstance(WEEK_OF_YEAR_FIELD);

System.out.println(now.format(REPLACE_HERE));

Which variable prints 2025-W01-2 (present-day is 12/31/2024)?

A.

format4

B.

format2

C.

format3

D.

format1

Showing 10 of 95 questions · Unlock the full set