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

Exact2Pass Menu

Question # 4

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?

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.

Full Access
Question # 5

Given:

java

var hauteCouture = new String[]{ "Chanel", "Dior", "Louis Vuitton" };

var i = 0;

do {

System.out.print(hauteCouture[i] + " ");

} while (i++ > 0);

What is printed?

A.

Chanel

B.

Chanel Dior Louis Vuitton

C.

An ArrayIndexOutOfBoundsException is thrown at runtime.

D.

Compilation fails.

Full Access
Question # 6

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

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

Full Access
Question # 7

Given:

java

Optional o1 = Optional.empty();

Optional o2 = Optional.of(1);

Optional o3 = Stream.of(o1, o2)

.filter(Optional::isPresent)

.findAny()

.flatMap(o -> o);

System.out.println(o3.orElse(2));

What is the given code fragment's output?

A.

1

B.

2

C.

Optional.empty

D.

0

E.

An exception is thrown

F.

Optional[1]

G.

Compilation fails

Full Access
Question # 8

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

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

Full Access
Question # 9

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?

A.

cbca

B.

acb

C.

cacb

D.

abc

E.

bca

F.

cba

G.

bac

Full Access
Question # 10

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?

A.

truetruefalse

B.

falsetruetrue

C.

truefalsetrue

D.

truetruetrue

E.

Compilation fails

Full Access
Question # 11

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?

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;

}

Full Access
Question # 12

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 # 13

Given:

java

List integers = List.of(0, 1, 2);

integers.stream()

.peek(System.out::print)

.limit(2)

.forEach(i -> {});

What is the output of the given code fragment?

A.

Compilation fails

B.

An exception is thrown

C.

01

D.

012

E.

Nothing

Full Access
Question # 14

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 # 15

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?

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

Full Access
Question # 16

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

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

}

Full Access
Question # 17

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?

A.

fos.write("Today");

B.

fos.writeObject("Today");

C.

oos.write("Today");

D.

oos.writeObject("Today");

Full Access
Question # 18

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 # 19

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 # 20

Given:

java

CopyOnWriteArrayList list = new CopyOnWriteArrayList<>();

list.add("A");

list.add("B");

list.add("C");

// Writing in one thread

new Thread(() -> {

list.add("D");

System.out.println("Element added: D");

}).start();

// Reading in another thread

new Thread(() -> {

for (String element : list) {

System.out.println("Read element: " + element);

}

}).start();

What is printed?

A.

It prints all elements, including changes made during iteration.

B.

It prints all elements, but changes made during iteration may not be visible.

C.

It throws an exception.

D.

Compilation fails.

Full Access
Question # 21

Given:

java

List frenchAuthors = new ArrayList<>();

frenchAuthors.add("Victor Hugo");

frenchAuthors.add("Gustave Flaubert");

Which compiles?

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

Full Access
Question # 22

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?

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.

Full Access
Question # 23

Given:

java

String textBlock = """

j \

a \t

v \s

a \

""";

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

What is the output?

A.

11

B.

12

C.

14

D.

10

Full Access
Question # 24

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?

A.

abc

B.

An exception is thrown.

C.

Compilation fails.

D.

ABC

Full Access
Question # 25

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