Pass the Oracle Java SE 1z0-830 Questions and answers with CertsForce

Viewing page 1 out of 3 pages
Viewing questions 1-10 out of questions
Questions # 1:

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


Expert Solution
Questions # 2:

Given:

java

String s = " ";

System.out.print("[" + s.strip());

s = " hello ";

System.out.print("," + s.strip());

s = "h i ";

System.out.print("," + s.strip() + "]");

What is printed?

Options:

A.

[ ,hello,h i]


B.

[,hello,h i]


C.

[,hello,hi]


D.

[ , hello ,hi ]


Expert Solution
Questions # 3:

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?

Options:

A.

1


B.

2


C.

Optional.empty


D.

0


E.

An exception is thrown


F.

Optional[1]


G.

Compilation fails


Expert Solution
Questions # 4:

Consider the following methods to load an implementation of MyService using ServiceLoader. Which of the methods are correct? (Choose all that apply)

Options:

A.

MyService service = ServiceLoader.load(MyService.class).iterator().next();


B.

MyService service = ServiceLoader.load(MyService.class).findFirst().get();


C.

MyService service = ServiceLoader.getService(MyService.class);


D.

MyService service = ServiceLoader.services(MyService.class).getFirstInstance();


Expert Solution
Questions # 5:

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


Expert Solution
Questions # 6:

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

}


Expert Solution
Questions # 7:

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?

Options:

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


Expert Solution
Questions # 8:

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.


Expert Solution
Questions # 9:

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


Expert Solution
Questions # 10:

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


Expert Solution
Viewing page 1 out of 3 pages
Viewing questions 1-10 out of questions