Question 31
Given the code fragments:
and
Which two modifications enable to sort the elements of the emps list? (Choose two.)
Question 32
Given the code fragment:
List<String> empDetails = Arrays.asList("100, Robin, HR",
"200, Mary, AdminServices",
"101, Peter, HR");
empDetails.stream()
.filter(s-> s.contains("1"))
.sorted()
.forEach(System.out::println); //line n1
What is the result?
Question 33
Given:
Item table
ID, INTEGER: PK
DESCRIP, VARCHAR(100)
PRICE, REAL
QUANTITY< INTEGER
And given the code fragment:
9. try {
10.Connection conn = DriveManager.getConnection(dbURL, username,
password);
11. String query = "Select * FROM Item WHERE ID = 110";
12. Statement stmt = conn.createStatement();
13. ResultSet rs = stmt.executeQuery(query);
14.while(rs.next()) {
15.System.out.println("ID:" + rs.getInt("Id"));
16.System.out.println("Description:" + rs.getString("Descrip"));
17.System.out.println("Price:" + rs.getDouble("Price"));
18. System.out.println(Quantity:" + rs.getInt("Quantity"));
19.}
20. } catch (SQLException se) {
21. System.out.println("Error");
22. }
Assume that:
- The required database driver is configured in the classpath.
- The appropriate database is accessible with the dbURL, userName, and
passWord exists.
- The SQL query is valid.
What is the result?
Question 34
Given the code fragment:
Which two modifications should you make so that the code compiles successfully?
Question 35
Given the code fragment:
public class FileThread implements Runnable {
String fName;
public FileThread(String fName) { this.fName = fName; }
public void run () System.out.println(fName);}
public static void main (String[] args) throws IOException,
InterruptedException {
ExecutorService executor = Executors.newCachedThreadPool();
Stream<Path> listOfFiles = Files.walk(Paths.get("Java Projects"));
listOfFiles.forEach(line -> {
executor.execute(new FileThread(line.getFileName().toString()));
//
line n1
});
executor.shutdown();
executor.awaitTermination(5, TimeUnit.DAYS); //
line n2
}
}
The Java Projectsdirectory exists and contains a list of files.
What is the result?
