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
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
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
DoubleStream doubleStream = DoubleStream.of(3.3, 4, 5.25, 6.66);
Predicate
System.out.println(doubleStream.anyMatch(doublePredicate));
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?
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
public class OuterClass {
String outerField = "Outer field";
class InnerClass {
void accessMembers() {
System.out.println(outerField);
}
}
public static void main(String[] args) {
System.out.println("Inner class:");
System.out.println("------------");
OuterClass outerObject = new OuterClass();
InnerClass innerObject = new InnerClass(); // n1
innerObject.accessMembers(); // n2
}
}
What is printed?
Given:
java
String textBlock = """
j \
a \t
v \s
a \
""";
System.out.println(textBlock.length());
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?
Given:
java
public class ThisCalls {
public ThisCalls() {
this(true);
}
public ThisCalls(boolean flag) {
this();
}
}
Which statement is correct?
Which of the following methods of java.util.function.Predicate aredefault methods?
Which three of the following are correct about the Java module system?
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
List
abc.stream()
.forEach(x -> {
x = x.toUpperCase();
});
abc.stream()
.forEach(System.out::print);
What is the output?
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));
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 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?
Which of the followingisn'ta correct way to write a string to a file?
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?
Given:
java
String colors = "red\n" +
"green\n" +
"blue\n";
Which text block can replace the above code?
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?
Which two of the following aren't the correct ways to create a Stream?
Given:
java
public class Test {
class A {
}
static class B {
}
public static void main(String[] args) {
// Insert here
}
}
Which three of the following are valid statements when inserted into the given program?
Which of the following isn't a valid option of the jdeps command?
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?