Given:
var cabarets = new TreeMap<>();
cabarets.put(1, "Moulin Rouge");
cabarets.put(2, "Crazy Horse");
cabarets.put(3, "Paradis Latin");
cabarets.put(4, "Le Lido");
cabarets.put(5, "Folies Bergère");
System.out.println(cabarets.subMap(2, true, 5, false));
What is printed?
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?
Given:
java
LocalDate localDate = LocalDate.of(2020, 8, 8);
Date date = java.sql.Date.valueOf(localDate);
DateFormat formatter = new SimpleDateFormat(/* pattern */);
String output = formatter.format(date);
System.out.println(output);
It's known that the given code prints out "August 08".
Which of the following should be inserted as the pattern?
How would you create a ConcurrentHashMap configured to allow a maximum of 10 concurrent writer threads and an initial capacity of 42?
Which of the following options meets this requirement?
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:
java
List
abc.stream()
.forEach(x -> {
x = x.toUpperCase();
});
abc.stream()
.forEach(System.out::print);
What is the output?
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?
Which StringBuilder variable fails to compile?
java
public class StringBuilderInstantiations {
public static void main(String[] args) {
var stringBuilder1 = new StringBuilder();
var stringBuilder2 = new StringBuilder(10);
var stringBuilder3 = new StringBuilder("Java");
var stringBuilder4 = new StringBuilder(new char[]{'J', 'a', 'v', 'a'});
}
}
Given:
java
final Stream
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?
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?
Consider the following methods to load an implementation of MyService using ServiceLoader. Which of the methods are correct? (Choose all that apply)
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?
Given:
java
StringBuffer us = new StringBuffer("US");
StringBuffer uk = new StringBuffer("UK");
Stream
String output = stream.collect(Collectors.joining("-", "=", ""));
System.out.println(output);
What is the given code fragment's output?
Given:
java
var deque = new ArrayDeque<>();
deque.add(1);
deque.add(2);
deque.add(3);
deque.add(4);
deque.add(5);
System.out.print(deque.peek() + " ");
System.out.print(deque.poll() + " ");
System.out.print(deque.pop() + " ");
System.out.print(deque.element() + " ");
What is printed?
Given:
java
var counter = 0;
do {
System.out.print(counter + " ");
} while (++counter < 3);
What is printed?
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?
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?
Which of the following methods of java.util.function.Predicate aredefault methods?