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

1z0-830 Questions and Answers

Question # 6

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?

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

Full Access
Question # 7

What do the following print?

java

public class DefaultAndStaticMethods {

public static void main(String[] args) {

WithStaticMethod.print();

}

}

interface WithDefaultMethod {

default void print() {

System.out.print("default");

}

}

interface WithStaticMethod extends WithDefaultMethod {

static void print() {

System.out.print("static");

}

}

A.

nothing

B.

default

C.

Compilation fails

D.

static

Full Access
Question # 8

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

Full Access
Question # 9

Given:

java

public class ThisCalls {

public ThisCalls() {

this(true);

}

public ThisCalls(boolean flag) {

this();

}

}

Which statement is correct?

A.

It does not compile.

B.

It throws an exception at runtime.

C.

It compiles.

Full Access
Question # 10

Given:

java

var lyrics = """

Quand il me prend dans ses bras

Qu'il me parle tout bas

Je vois la vie en rose

""";

for ( int i = 0, int j = 3; i < j; i++ ) {

System.out.println( lyrics.lines()

.toList()

.get( i ) );

}

What is printed?

A.

vbnet

Quand il me prend dans ses bras

Qu'il me parle tout bas

Je vois la vie en rose

B.

Nothing

C.

An exception is thrown at runtime.

D.

Compilation fails.

Full Access
Question # 11

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

Full Access
Question # 12

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?

A.

0

B.

1

C.

2

D.

It throws an exception at runtime.

E.

Compilation fails.

Full Access
Question # 13

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?

A.

1

B.

2

C.

Compilation fails

D.

ClassCastException

E.

NotSerializableException

Full Access
Question # 14

Which of the following doesnotexist?

A.

BooleanSupplier

B.

DoubleSupplier

C.

LongSupplier

D.

Supplier<T>

E.

BiSupplier<T, U, R>

F.

They all exist.

Full Access
Question # 15

Which of the following java.io.Console methods doesnotexist?

A.

read()

B.

reader()

C.

readLine()

D.

readLine(String fmt, Object... args)

E.

readPassword()

F.

readPassword(String fmt, Object... args)

Full Access
Question # 16

Given:

java

public class OuterClass {

String outerField = "Outer field";

class InnerClass {

void accessMembers() {

System.out.println(outerField);

}

}

public static void main(String[] args) {

System.out.println("Inner class:");

System.out.println("------------");

OuterClass outerObject = new OuterClass();

InnerClass innerObject = new InnerClass(); // n1

innerObject.accessMembers(); // n2

}

}

What is printed?

A.

markdown

Inner class:

------------

Outer field

B.

Nothing

C.

An exception is thrown at runtime.

D.

Compilation fails at line n1.

E.

Compilation fails at line n2.

Full Access
Question # 17

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?

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

Full Access
Question # 18

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?

A.

Compilation fails

B.

true

C.

false

D.

An exception is thrown at runtime

E.

3.3

Full Access
Question # 19

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?

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

Full Access
Question # 20

What does the following code print?

java

import java.util.stream.Stream;

public class StreamReduce {

public static void main(String[] args) {

Stream stream = Stream.of("J", "a", "v", "a");

System.out.print(stream.reduce(String::concat));

}

}

A.

Optional[Java]

B.

Java

C.

null

D.

Compilation fails

Full Access
Question # 21

Which of the following methods of java.util.function.Predicate aredefault methods?

A.

and(Predicate<? super T> other)

B.

isEqual(Object targetRef)

C.

negate()

D.

not(Predicate<? super T> target)

E.

or(Predicate<? super T> other)

F.

test(T t)

Full Access
Question # 22

Given:

java

interface A {

default void ma() {

}

}

interface B extends A {

static void mb() {

}

}

interface C extends B {

void ma();

void mc();

}

interface D extends C {

void md();

}

interface E extends D {

default void ma() {

}

default void mb() {

}

default void mc() {

}

}

Which interface can be the target of a lambda expression?

A.

None of the above

B.

C

C.

A

D.

E

E.

B

F.

D

Full Access
Question # 23

Given:

java

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

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

Full Access
Question # 24

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.

Full Access
Question # 25

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.

Full Access