Special Summer Sale 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: save70

Free and Premium Oracle 1z0-830 Dumps Questions Answers

Page: 1 / 6
Total 84 questions

Java SE 21 Developer Professional Questions and Answers

Question 1

Given:

java

double amount = 42_000.00;

NumberFormat format = NumberFormat.getCompactNumberInstance(Locale.FRANCE, NumberFormat.Style.SHORT);

System.out.println(format.format(amount));

What is the output?

Options:

A.

42000E

B.

42 000,00 €

C.

42000

D.

42 k

Buy Now
Question 2

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 3

Given:

java

record WithInstanceField(String foo, int bar) {

double fuz;

}

record WithStaticField(String foo, int bar) {

static double wiz;

}

record ExtendingClass(String foo) extends Exception {}

record ImplementingInterface(String foo) implements Cloneable {}

Which records compile? (Select 2)

Options:

A.

ExtendingClass

B.

WithInstanceField

C.

ImplementingInterface

D.

WithStaticField

Question 4

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 5

Given:

java

Runnable task1 = () -> System.out.println("Executing Task-1");

Callable task2 = () -> {

System.out.println("Executing Task-2");

return "Task-2 Finish.";

};

ExecutorService execService = Executors.newCachedThreadPool();

// INSERT CODE HERE

execService.awaitTermination(3, TimeUnit.SECONDS);

execService.shutdownNow();

Which of the following statements, inserted in the code above, printsboth:

"Executing Task-2" and "Executing Task-1"?

Options:

A.

execService.call(task1);

B.

execService.call(task2);

C.

execService.execute(task1);

D.

execService.execute(task2);

E.

execService.run(task1);

F.

execService.run(task2);

G.

execService.submit(task1);

Question 6

You are working on a module named perfumery.shop that depends on another module named perfumery.provider.

The perfumery.shop module should also make its package perfumery.shop.eaudeparfum available to other modules.

Which of the following is the correct file to declare the perfumery.shop module?

Options:

A.

File name: module-info.perfumery.shop.java

java

module perfumery.shop {

requires perfumery.provider;

exports perfumery.shop.eaudeparfum.*;

}

B.

File name: module-info.java

java

module perfumery.shop {

requires perfumery.provider;

exports perfumery.shop.eaudeparfum;

}

C.

File name: module.java

java

module shop.perfumery {

requires perfumery.provider;

exports perfumery.shop.eaudeparfum;

}

Question 7

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

}

Question 8

Given:

java

interface SmartPhone {

boolean ring();

}

class Iphone15 implements SmartPhone {

boolean isRinging;

boolean ring() {

isRinging = !isRinging;

return isRinging;

}

}

Choose the right statement.

Options:

A.

Iphone15 class does not compile

B.

Everything compiles

C.

SmartPhone interface does not compile

D.

An exception is thrown at running Iphone15.ring();

Question 9

Given:

java

var sList = new CopyOnWriteArrayList();

Which of the following statements is correct?

Options:

A.

The CopyOnWriteArrayList class is a thread-safe variant of ArrayList where all mutative operations are implemented by making a fresh copy of the underlying array.

B.

The CopyOnWriteArrayList class is not thread-safe and does not prevent interference amongconcurrent threads.

C.

The CopyOnWriteArrayList class’s iterator reflects all additions, removals, or changes to the list since the iterator was created.

D.

The CopyOnWriteArrayList class does not allow null elements.

E.

Element-changing operations on iterators of CopyOnWriteArrayList, such as remove, set, and add, are supported and do not throw UnsupportedOperationException.

Question 10

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

Question 11

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

Question 12

Which of the following doesnotexist?

Options:

A.

BooleanSupplier

B.

DoubleSupplier

C.

LongSupplier

D.

Supplier<T>

E.

BiSupplier<T, U, R>

F.

They all exist.

Question 13

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 14

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?

Options:

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.

Question 15

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 16

Given:

java

public class BoomBoom implements AutoCloseable {

public static void main(String[] args) {

try (BoomBoom boomBoom = new BoomBoom()) {

System.out.print("bim ");

throw new Exception();

} catch (Exception e) {

System.out.print("boom ");

}

}

@Override

public void close() throws Exception {

System.out.print("bam ");

throw new RuntimeException();

}

}

What is printed?

Options:

A.

bim boom bam

B.

bim bam boom

C.

bim boom

D.

bim bam followed by an exception

E.

Compilation fails.

Question 17

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 18

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

}

}

Options:

A.

nothing

B.

default

C.

Compilation fails

D.

static

Question 19

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 20

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 21

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 22

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 23

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

Question 24

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?

Options:

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

Options:

A.

integer

B.

long

C.

string

D.

nothing

E.

It throws an exception at runtime.

F.

Compilation fails.

Page: 1 / 6
Total 84 questions