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?
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?
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)
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?
Given:
java
Runnable task1 = () -> System.out.println("Executing Task-1");
Callable
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"?
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?
Which methods compile?
Given:
java
interface SmartPhone {
boolean ring();
}
class Iphone15 implements SmartPhone {
boolean isRinging;
boolean ring() {
isRinging = !isRinging;
return isRinging;
}
}
Choose the right statement.
Given:
java
var sList = new CopyOnWriteArrayList
Which of the following statements is correct?
Given:
java
Deque
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?
Given:
java
Stream
BinaryOperator
String result = strings.reduce("-", operator);
System.out.println(result);
What is the output of this code fragment?
Which of the following doesnotexist?
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?
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?
Which of the following methods of java.util.function.Predicate aredefault methods?
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?
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));
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");
}
}
What does the following code print?
java
import java.util.stream.Stream;
public class StreamReduce {
public static void main(String[] args) {
Stream
System.out.print(stream.reduce(String::concat));
}
}
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?
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?
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?
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?
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?
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?