Weekend Biggest Discount Flat 70% Offer - Ends in 0d 00h 00m 00s - Coupon code: 70diswrap

Oracle 1z0-830 Dumps

Page: 1 / 8
Total 84 questions

Java SE 21 Developer Professional Questions and Answers

Question 1

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 2

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

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

var array1 = new String[]{ "foo", "bar", "buz" };

var array2[] = { "foo", "bar", "buz" };

var array3 = new String[3] { "foo", "bar", "buz" };

var array4 = { "foo", "bar", "buz" };

String array5[] = new String[]{ "foo", "bar", "buz" };

Which arrays compile? (Select 2)

Options:

A.

array1

B.

array2

C.

array3

D.

array4

E.

array5

Question 5

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?

Options:

A.

[a, b]

B.

[d, b]

C.

[c, b]

D.

An UnsupportedOperationException is thrown

E.

An IndexOutOfBoundsException is thrown

F.

[d]

Question 6

Given:

java

public class Versailles {

int mirrorsCount;

int gardensHectares;

void Versailles() { // n1

this.mirrorsCount = 17;

this.gardensHectares = 800;

System.out.println("Hall of Mirrors has " + mirrorsCount + " mirrors.");

System.out.println("The gardens cover " + gardensHectares + " hectares.");

}

public static void main(String[] args) {

var castle = new Versailles(); // n2

}

}

What is printed?

Options:

A.

nginx

Hall of Mirrors has 17 mirrors.

The gardens cover 800 hectares.

B.

Nothing

C.

An exception is thrown at runtime.

D.

Compilation fails at line n1.

E.

Compilation fails at line n2.

Question 7

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 8

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

Options:

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

Question 9

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?

Options:

A.

fos.write("Today");

B.

fos.writeObject("Today");

C.

oos.write("Today");

D.

oos.writeObject("Today");

Question 10

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 11

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

Question 12

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?

Options:

A.

US-UK

B.

An exception is thrown.

C.

-US=UK

D.

=US-UK

E.

Compilation fails.

F.

US=UK

Question 13

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 14

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.

Question 15

Given:

java

public class ExceptionPropagation {

public static void main(String[] args) {

try {

thrower();

System.out.print("Dom Pérignon, ");

} catch (Exception e) {

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

} finally {

System.out.print("Saint-Émilion");

}

}

static int thrower() {

try {

int i = 0;

return i / i;

} catch (NumberFormatException e) {

System.out.print("Rosé");

return -1;

} finally {

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

}

}

}

What is printed?

Options:

A.

Saint-Émilion

B.

Beaujolais Nouveau, Chablis, Saint-Émilion

C.

Beaujolais Nouveau, Chablis, Dom Pérignon, Saint-Émilion

D.

Rosé

Question 16

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 17

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 18

Given:

java

sealed class Vehicle permits Car, Bike {

}

non-sealed class Car extends Vehicle {

}

final class Bike extends Vehicle {

}

public class SealedClassTest {

public static void main(String[] args) {

Class vehicleClass = Vehicle.class;

Class carClass = Car.class;

Class bikeClass = Bike.class;

System.out.print("Is Vehicle sealed? " + vehicleClass.isSealed() +

"; Is Car sealed? " + carClass.isSealed() +

"; Is Bike sealed? " + bikeClass.isSealed());

}

}

What is printed?

Options:

A.

Is Vehicle sealed? true; Is Car sealed? true; Is Bike sealed? true

B.

Is Vehicle sealed? false; Is Car sealed? false; Is Bike sealed? false

C.

Is Vehicle sealed? true; Is Car sealed? false; Is Bike sealed? false

D.

Is Vehicle sealed? false; Is Car sealed? true; Is Bike sealed? true

Question 19

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

Question 20

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?

Options:

A.

true

B.

false

C.

A NullPointerException is thrown.

D.

A ClassCastException is thrown.

E.

Compilation fails.

Question 21

A module com.eiffeltower.shop with the related sources in the src directory.

That module requires com.eiffeltower.membership, available in a JAR located in the lib directory.

What is the command to compile the module com.eiffeltower.shop?

Options:

A.

bash

CopyEdit

javac -source src -p lib/com.eiffel.membership.jar -d out -m com.eiffeltower.shop

B.

css

CopyEdit

javac --module-source-path src -p lib/com.eiffel.membership.jar -d out -m com.eiffeltower.shop

C.

css

CopyEdit

javac --module-source-path src -p lib/com.eiffel.membership.jar -s out -m com.eiffeltower.shop

D.

css

CopyEdit

javac -path src -p lib/com.eiffel.membership.jar -d out -m com.eiffeltower.shop

Question 22

Given:

java

void verifyNotNull(Object input) {

boolean enabled = false;

assert enabled = true;

assert enabled;

System.out.println(input.toString());

assert input != null;

}

When does the given method throw a NullPointerException?

Options:

A.

A NullPointerException is never thrown

B.

Only if assertions are enabled and the input argument is null

C.

Only if assertions are disabled and the input argument is null

D.

Only if assertions are enabled and the input argument isn't null

E.

Only if assertions are disabled and the input argument isn't null

Question 23

Given:

java

var _ = 3;

var $ = 7;

System.out.println(_ + $);

What is printed?

Options:

A.

10

B.

_$

C.

It throws an exception.

D.

Compilation fails.

Question 24

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

Question 25

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?

Options:

A.

Compilation fails

B.

IOException

C.

RuntimeException

D.

ArithmeticException

Page: 1 / 8
Total 84 questions