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

1z0-830 Java SE 21 Developer Professional Questions and Answers

Questions 4

Given:

java

var counter = 0;

do {

System.out.print(counter + " ");

} while (++counter < 3);

What is printed?

Options:

A.

0 1 2 3

B.

0 1 2

C.

1 2 3 4

D.

1 2 3

E.

An exception is thrown.

F.

Compilation fails.

Buy Now
Questions 5

Given:

java

Object input = 42;

String result = switch (input) {

case String s -> "It's a string with value: " + s;

case Double d -> "It's a double with value: " + d;

case Integer i -> "It's an integer with value: " + i;

};

System.out.println(result);

What is printed?

Options:

A.

null

B.

It's a string with value: 42

C.

It's a double with value: 42

D.

It's an integer with value: 42

E.

It throws an exception at runtime.

F.

Compilation fails.

Buy Now
Questions 6

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

Buy Now
Questions 7

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.

Buy Now
Questions 8

Which methods compile?

Options:

A.

```java public List getListSuper() { return new ArrayList(); }

csharp

B.

```java

public List getListExtends() {

return new ArrayList();

}

C.

```java public List getListExtends() { return new ArrayList(); }

csharp

D.

```java

public List getListSuper() {

return new ArrayList();

}

Buy Now
Questions 9

Given:

java

List cannesFestivalfeatureFilms = LongStream.range(1, 1945)

.boxed()

.toList();

try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {

cannesFestivalfeatureFilms.stream()

.limit(25)

.forEach(film -> executor.submit(() -> {

System.out.println(film);

}));

}

What is printed?

Options:

A.

Numbers from 1 to 25 sequentially

B.

Numbers from 1 to 25 randomly

C.

Numbers from 1 to 1945 randomly

D.

An exception is thrown at runtime

E.

Compilation fails

Buy Now
Questions 10

Given:

java

Period p = Period.between(

LocalDate.of(2023, Month.MAY, 4),

LocalDate.of(2024, Month.MAY, 4));

System.out.println(p);

Duration d = Duration.between(

LocalDate.of(2023, Month.MAY, 4),

LocalDate.of(2024, Month.MAY, 4));

System.out.println(d);

What is the output?

Options:

A.

P1Y

PT8784H

B.

PT8784H

P1Y

C.

UnsupportedTemporalTypeException

D.

P1Y

UnsupportedTemporalTypeException

Buy Now
Questions 11

Given:

java

Deque deque = new ArrayDeque<>();

deque.offer(1);

deque.offer(2);

var i1 = deque.peek();

var i2 = deque.poll();

var i3 = deque.peek();

System.out.println(i1 + " " + i2 + " " + i3);

What is the output of the given code fragment?

Options:

A.

1 2 1

B.

An exception is thrown.

C.

2 2 1

D.

2 1 2

E.

1 2 2

F.

1 1 2

G.

2 1 1

Buy Now
Questions 12

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?

Options:

A.

integer

B.

long

C.

string

D.

nothing

E.

It throws an exception at runtime.

F.

Compilation fails.

Buy Now
Questions 13

Given:

java

List frenchAuthors = new ArrayList<>();

frenchAuthors.add("Victor Hugo");

frenchAuthors.add("Gustave Flaubert");

Which compiles?

Options:

A.

Map<String, ArrayList<String>> authorsMap1 = new HashMap<>();

java

authorsMap1.put("FR", frenchAuthors);

B.

Map<String, ? extends List<String>> authorsMap2 = new HashMap<String, ArrayList<String>>();

java

authorsMap2.put("FR", frenchAuthors);

C.

var authorsMap3 = new HashMap<>();

java

authorsMap3.put("FR", frenchAuthors);

D.

Map<String, List<String>> authorsMap4 = new HashMap<String, ArrayList<String>>();

java

authorsMap4.put("FR", frenchAuthors);

E.

Map<String, List<String>> authorsMap5 = new HashMap<String, List<String>>();

java

authorsMap5.put("FR", frenchAuthors);

Buy Now
Questions 14

What do the following print?

java

public class Main {

int instanceVar = staticVar;

static int staticVar = 666;

public static void main(String args[]) {

System.out.printf("%d %d", new Main().instanceVar, staticVar);

}

static {

staticVar = 42;

}

}

Options:

A.

666 42

B.

666 666

C.

42 42

D.

Compilation fails

Buy Now
Questions 15

Given:

java

interface Calculable {

long calculate(int i);

}

public class Test {

public static void main(String[] args) {

Calculable c1 = i -> i + 1; // Line 1

Calculable c2 = i -> Long.valueOf(i); // Line 2

Calculable c3 = i -> { throw new ArithmeticException(); }; // Line 3

}

}

Which lines fail to compile?

Options:

A.

Line 1 and line 3

B.

Line 2 only

C.

Line 1 only

D.

Line 1 and line 2

E.

Line 2 and line 3

F.

Line 3 only

G.

The program successfully compiles

Buy Now
Questions 16

Given:

java

LocalDate localDate = LocalDate.of(2020, 8, 8);

Date date = java.sql.Date.valueOf(localDate);

DateFormat formatter = new SimpleDateFormat(/* pattern */);

String output = formatter.format(date);

System.out.println(output);

It's known that the given code prints out "August 08".

Which of the following should be inserted as the pattern?

Options:

A.

MM d

B.

MM dd

C.

MMMM dd

D.

MMM dd

Buy Now
Questions 17

Given:

java

public class SpecialAddition extends Addition implements Special {

public static void main(String[] args) {

System.out.println(new SpecialAddition().add());

}

int add() {

return --foo + bar--;

}

}

class Addition {

int foo = 1;

}

interface Special {

int bar = 1;

}

What is printed?

Options:

A.

0

B.

1

C.

2

D.

It throws an exception at runtime.

E.

Compilation fails.

Buy Now
Questions 18

Given:

java

var deque = new ArrayDeque<>();

deque.add(1);

deque.add(2);

deque.add(3);

deque.add(4);

deque.add(5);

System.out.print(deque.peek() + " ");

System.out.print(deque.poll() + " ");

System.out.print(deque.pop() + " ");

System.out.print(deque.element() + " ");

What is printed?

Options:

A.

1 1 1 1

B.

1 5 5 1

C.

1 1 2 3

D.

1 1 2 2

E.

5 5 2 3

Buy Now
Questions 19

Consider the following methods to load an implementation of MyService using ServiceLoader. Which of the methods are correct? (Choose all that apply)

Options:

A.

MyService service = ServiceLoader.load(MyService.class).iterator().next();

B.

MyService service = ServiceLoader.load(MyService.class).findFirst().get();

C.

MyService service = ServiceLoader.getService(MyService.class);

D.

MyService service = ServiceLoader.services(MyService.class).getFirstInstance();

Buy Now
Questions 20

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

Options:

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.

Buy Now
Questions 21

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

Options:

A.

format4

B.

format2

C.

format3

D.

format1

Buy Now
Questions 22

Given:

java

DoubleStream doubleStream = DoubleStream.of(3.3, 4, 5.25, 6.66);

Predicate doublePredicate = d -> d < 5;

System.out.println(doubleStream.anyMatch(doublePredicate));

What is printed?

Options:

A.

Compilation fails

B.

true

C.

false

D.

An exception is thrown at runtime

E.

3.3

Buy Now
Questions 23

Given:

java

Stream strings = Stream.of("United", "States");

BinaryOperator operator = (s1, s2) -> s1.concat(s2.toUpperCase());

String result = strings.reduce("-", operator);

System.out.println(result);

What is the output of this code fragment?

Options:

A.

United-States

B.

United-STATES

C.

UNITED-STATES

D.

-UnitedStates

E.

-UNITEDSTATES

F.

-UnitedSTATES

G.

UnitedStates

Buy Now
Questions 24

Given:

java

import java.io.*;

class A implements Serializable {

int number = 1;

}

class B implements Serializable {

int number = 2;

}

public class Test {

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

File file = new File("o.ser");

A a = new A();

var oos = new ObjectOutputStream(new FileOutputStream(file));

oos.writeObject(a);

oos.close();

var ois = new ObjectInputStream(new FileInputStream(file));

B b = (B) ois.readObject();

ois.close();

System.out.println(b.number);

}

}

What is the given program's output?

Options:

A.

1

B.

2

C.

Compilation fails

D.

ClassCastException

E.

NotSerializableException

Buy Now
Questions 25

Which of the following isn't a valid option of the jdeps command?

Options:

A.

--check-deps

B.

--generate-open-module

C.

--list-deps

D.

--generate-module-info

E.

--print-module-deps

F.

--list-reduced-deps

Buy Now
Exam Code: 1z0-830
Exam Name: Java SE 21 Developer Professional
Last Update: Jun 16, 2025
Questions: 84
1z0-830 pdf

1z0-830 PDF

$29.75  $84.99
1z0-830 Engine

1z0-830 Testing Engine

$35  $99.99
1z0-830 PDF + Engine

1z0-830 PDF + Testing Engine

$47.25  $134.99