Given the code fragment:
Path file = Paths.get ("courses.txt"); // line n1
Assume the courses.txt is accessible.
Which code fragment can be inserted at line n1 to enable the code to print the content of the courses.txt file?
A. List
B. Stream
C. List
D. Stream
Given:
class Book {
int id;
String name;
public Book (int id, String name) {
this.id = id;
this.name = name;
}
public boolean equals (Object obj) { //line n1
boolean output = false;
Book b = (Book) obj;
if (this.name.equals(b name))}
output = true;
}
return output;
}
}
and the code fragment:
Book b1 = new Book (101, "Java Programing");
Book b2 = new Book (102, "Java Programing");
System.out.println (b1.equals(b2)); //line n2
Which statement is true?
A. The program prints true.
B. The program prints false.
C. A compilation error occurs. To ensure successful compilation, replace line n1 with: boolean equals (Book obj) {
D. A compilation error occurs. To ensure successful compilation, replace line n2 with: System.out.println (b1.equals((Object) b2));
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) 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:

What is the result?
A. true true
B. false true
C. false false
D. true false
Given the code fragment: Assume that the value of now is 6:30 in the morning. What is the result?

A. An exception is thrown at run time.
B. 0
C. 60
D. 1
Given the code fragments: and


What is the result?
A. Video played.Game played.
B. A compilation error occurs.
C. class java.lang.Exception
D. class java.io.IOException
Given records from the Player table:

and given the code fragment:
try {
Connection conn = DriverManager.getConnection(URL, username, password);
Statement st= conn.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
st.execute ("SELECT * FROM Player");
st.setMaxRows(2);
ResultSet rs = st.getResultSet();
rs.absolute(3);
while (rs.next ()) {
System.out.println(rs.getInt(1) + " " + rs.getString(2));
}
} catch (SQLException ex) {
System.out.print("SQLException is thrown.");
}
Assume that:
The required database driver is configured in the classpath.
The appropriate database is accessible with URL, username, and password.
The SQL query is valid.
What is the result?
A. 2 Jack 3 Sam
B. The program prints nothing.
C. 3 Sam
D. SQLException is thrown.
Given the code fragments:
interface CourseFilter extends Predicate
return str.contains ("Java");
}
}
and
List
Predicate
Predicate cf2 = new CourseFilter() { //line n1
public boolean test (String s) {
return s.startsWith ("Java");
}
};
long c = strs.stream()
.filter(cf1)
.filter(cf2 //line n2
.count();
System.out.println(c);
What is the result?
A. 2
B. 3
C. A compilation error occurs at line n1.
D. A compilation error occurs at line n2.
Given the code fragment:
Map
books.put (1007, "A");
books.put (1002, "C");
books.put (1003, "B");
books.put (1003, "B");
System.out.println (books);
What is the result?
A. {1007=A, 1003=B, 1002=C}
B. {1007=A, 1003=B, 1003=B, 1002=C}
C. {1007=A, 1002=C, 1003=B, 1003=B}
D. {1002=C, 1003=B, 1007=A}
Given the code fragment:
Stream
line n1
try {
Path aPath = fName.toAbsolutePath(); //line n2
System.out.println(fName + ":"
+ Files.readAttributes(aPath, Basic.File.Attributes.class).creationTime
());
} catch (IOException ex) {
ex.printStackTrace();
});
What is the result?
A. All files and directories under the home directory are listed along with their attributes.
B. A compilation error occurs at line n1.
C. The files in the home directory are listed along with their attributes.
D. A compilation error occurs at line n2.