Given:
public class Emp {
String fName;
String lName;
public Emp (String fn, String ln) {
fName = fn;
lName = ln;
}
public String getfName() { return fName; }
public String getlName() { return lName; }
}
and the code fragment:
List
new Emp ("John", "Smith"),
new Emp ("Peter", "Sam"),
new Emp ("Thomas", "Wale"));
emp.stream()
//line n1
.collect(Collectors.toList());
Which code fragment, when inserted at line n1, sorts the employees list in descending order of fName and
then ascending order of lName?
A. .sorted (Comparator.comparing(Emp::getfName).reserved().thenComparing(Emp::getlName))
B. .sorted (Comparator.comparing(Emp::getfName).thenComparing(Emp::getlName))
C. .map(Emp::getfName).sorted(Comparator.reserveOrder())
D. .map(Emp::getfName).sorted(Comparator.reserveOrder().map(Emp::getlName).reserved
Given the definition of the Vehicle class:
class Vehicle {
String name;
void setName (String name) {
this.name = name;
}
String getName() {
return name;
}
}
Which action encapsulates the Vehicle class?
A. Make the Vehicle class public.
B. Make the name variable public.
C. Make the setName method public.
D. Make the name variable private.
E. Make the setName method private.
F. Make the getName method private.
You want to create a singleton class by using the Singleton design pattern. Which two statements enforce the singleton nature of the design? (Choose two.)
A. Make the class static.
B. Make the constructor private.
C. Override equals() and hashCode() methods of the java.lang.Object class.
D. Use a static reference to point to the single instance.
E. Implement the Serializable interface.
Given the code fragment:
UnaryOperator
List
loanValues.stream()
.filter(lv -> lv >= 1500)
.map(lv -> uo1.apply(lv))
.forEach(s -> System.out.print(s + " "));
What is the result?
A. 4000.0
B. 4000
C. A compilation error occurs at line n1.
D. A compilation error occurs at line n2.
Given the code fragment:
Assume that:
The required database driver is configured in the classpath.
The appropriate database is accessible with the dbURL, userName, and passWord exists
The Employee table has a column ID of type integer and the SQL query matches one record.
What is the result?
A. Compilation fails at line 14.
B. Compilation fails at line 15.
C. The code prints the employee ID.
D. The code prints Error.
Given the code fragment:
Which modification enables the code to print Price 5 New Price 4?
A. Replace line n2 with .map (n -> System.out.println (“New Price” + n –1)) and remove line n3
B. Replace line n2 with .mapToInt (n -> n – 1);
C. Replace line n1 with .forEach (e -> System.out.print (“Price” + e))
D. Replace line n3 with .forEach (n -> System.out.println (“New Price” + n));
Given the records from the STUDENT table:
Given the code fragment:
Assume that the URL, username, and password are valid.
What is the result?
A. The STUDENT table is not updated and the program prints:
114 : John : [email protected]
B. The STUDENT table is updated with the record:
113 : Jannet : [email protected]
and the program prints:
114 : John : [email protected]
C. The STUDENT table is updated with the record:
113 : Jannet : [email protected]
and the program prints:
113 : Jannet : [email protected]
D. A SQLException is thrown at run time.
Given that these files exist and are accessible:
/sports/info.txt
/sports/cricket/players.txt
/sports/cricket/data/ODI.txt
and given the code fragment:
int maxDepth =2;
Stream
maxDepth,
(p, a) -> p.getFileName().toString().endsWith ("txt"),
FileVisitOption.FOLLOW_LINKS);
Long fCount = paths.count();
System.out.println(fCount);
Assuming that there are NO soft-link/symbolic links to any of the files in the directory structure, what is the
result?
A. 1
B. 2
C. 3
D. An Exception is thrown at runtime.
Given the code fragments:
class Caller implements Callable
String str;
public Caller (String s) {this.str=s;}
public String call()throws Exception { return str.concat ("Caller");}
}
class Runner implements Runnable {
String str;
public Runner (String s) {this.str=s;}
public void run () { System.out.println (str.concat ("Runner"));}
}
and
public static void main (String[] args) throws InterruptedException, ExecutionException { ExecutorService
es = Executors.newFixedThreadPool(2);
Future f1 = es.submit (new Caller ("Call"));
Future f2 = es.submit (new Runner ("Run"));
String str1 = (String) f1.get();
String str2 = (String) f2.get(); //line n1
System.out.println(str1+ ":" + str2);
}
What is the result?
A. The program prints:
Run Runner
Call Caller : null
And the program does not terminate.
B. The program terminates after printing: Run Runner Call Caller : Run
C. A compilation error occurs at line n1.
D. An Execution is thrown at run time.
Given:
and the code fragment:
Which code fragment can be inserted to print 13?
A. Option A
B. Option B
C. Option C
D. Option D