Weekend Special Limited Time 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: 70special

Oracle 1z0-830 Java SE 21 Developer Professional Exam Practice Test

Page: 1 / 8
Total 84 questions

Java SE 21 Developer Professional Questions and Answers

Testing Engine

  • Product Type: Testing Engine
$37.5  $124.99

PDF Study Guide

  • Product Type: PDF Study Guide
$33  $109.99
Question 1

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

Question 2

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.

Question 3

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

Question 4

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

Question 5

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

Question 6

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?

Options:

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

Question 7

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?

Options:

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.

Question 8

Given:

java

String textBlock = """

j \

a \t

v \s

a \

""";

System.out.println(textBlock.length());

What is the output?

Options:

A.

11

B.

12

C.

14

D.

10

Question 9

Given:

java

var ceo = new HashMap<>();

ceo.put("Sundar Pichai", "Google");

ceo.put("Tim Cook", "Apple");

ceo.put("Mark Zuckerberg", "Meta");

ceo.put("Andy Jassy", "Amazon");

Does the code compile?

Options:

A.

True

B.

False

Question 10

Given:

java

public class ThisCalls {

public ThisCalls() {

this(true);

}

public ThisCalls(boolean flag) {

this();

}

}

Which statement is correct?

Options:

A.

It does not compile.

B.

It throws an exception at runtime.

C.

It compiles.

Question 11

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

Options:

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)

Question 12

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.

Question 13

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

}

}

Options:

A.

Optional[Java]

B.

Java

C.

null

D.

Compilation fails

Question 14

Given:

java

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

abc.stream()

.forEach(x -> {

x = x.toUpperCase();

});

abc.stream()

.forEach(System.out::print);

What is the output?

Options:

A.

abc

B.

An exception is thrown.

C.

Compilation fails.

D.

ABC

Question 15

What is the output of the following snippet? (Assume the file exists)

java

Path path = Paths.get("C:\\home\\joe\\foo");

System.out.println(path.getName(0));

Options:

A.

C:

B.

IllegalArgumentException

C.

C

D.

Compilation error

E.

home

Question 16

Given:

java

DoubleSummaryStatistics stats1 = new DoubleSummaryStatistics();

stats1.accept(4.5);

stats1.accept(6.0);

DoubleSummaryStatistics stats2 = new DoubleSummaryStatistics();

stats2.accept(3.0);

stats2.accept(8.5);

stats1.combine(stats2);

System.out.println("Sum: " + stats1.getSum() + ", Max: " + stats1.getMax() + ", Avg: " + stats1.getAverage());

What is printed?

Options:

A.

Sum: 22.0, Max: 8.5, Avg: 5.5

B.

Sum: 22.0, Max: 8.5, Avg: 5.0

C.

An exception is thrown at runtime.

D.

Compilation fails.

Question 17

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?

Options:

A.

MissingResourceException

B.

Compilation fails

C.

James

D.

JeanneJames

E.

JamesJeanne

F.

Jeanne

Question 18

Which of the followingisn'ta correct way to write a string to a file?

Options:

A.

java

Path path = Paths.get("file.txt");

byte[] strBytes = "Hello".getBytes();

Files.write(path, strBytes);

B.

java

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.

java

try (PrintWriter printWriter = new PrintWriter("file.txt")) {

printWriter.printf("Hello %s", "James");

}

E.

None of the suggestions

F.

java

try (FileWriter writer = new FileWriter("file.txt")) {

writer.write("Hello");

}

Question 19

Given:

java

StringBuilder result = Stream.of("a", "b")

.collect(

() -> new StringBuilder("c"),

StringBuilder::append,

(a, b) -> b.append(a)

);

System.out.println(result);

What is the output of the given code fragment?

Options:

A.

cbca

B.

acb

C.

cacb

D.

abc

E.

bca

F.

cba

G.

bac

Question 20

Given:

java

String colors = "red\n" +

"green\n" +

"blue\n";

Which text block can replace the above code?

Options:

A.

java

String colors = """

red \

green\

blue \

""";

B.

java

String colors = """

red \s

green\s

blue \s

""";

C.

java

String colors = """

red \t

green\t

blue \t

""";

D.

java

String colors = """

red

green

blue

""";

E.

None of the propositions

Question 21

Given:

java

final Stream strings =

Files.readAllLines(Paths.get("orders.csv"));

strings.skip(1)

.limit(2)

.forEach(System.out::println);

And that the orders.csv file contains:

mathematica

OrderID,Customer,Product,Quantity,Price

1,Kylian Mbappé,Keyboard,2,25.50

2,Teddy Riner,Mouse,1,15.99

3,Sebastien Loeb,Monitor,1,199.99

4,Antoine Griezmann,Headset,3,45.00

What is printed?

Options:

A.

arduino

1,Kylian Mbappé,Keyboard,2,25.50

2,Teddy Riner,Mouse,1,15.99

3,Sebastien Loeb,Monitor,1,199.99

4,Antoine Griezmann,Headset,3,45.00

B.

arduino

1,Kylian Mbappé,Keyboard,2,25.50

2,Teddy Riner,Mouse,1,15.99

C.

arduino

2,Teddy Riner,Mouse,1,15.99

3,Sebastien Loeb,Monitor,1,199.99

D.

An exception is thrown at runtime.

E.

Compilation fails.

Question 22

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

Options:

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 stream = Stream.builder().add("a").build();

G.

Stream stream = Stream.empty();

Question 23

Given:

java

public class Test {

class A {

}

static class B {

}

public static void main(String[] args) {

// Insert here

}

}

Which three of the following are valid statements when inserted into the given program?

Options:

A.

A a = new A();

B.

B b = new Test.B();

C.

A a = new Test.A();

D.

B b = new Test().new B();

E.

B b = new B();

F.

A a = new Test().new A();

Question 24

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

Question 25

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

Page: 1 / 8
Total 84 questions