MultipleChoice
Given the code fragment:
BiFunction<Integer, Double, Integer> val = (t1, t2) -> t1 + t2; //line n1
//line n2
System.out.println(val.apply(10, 10.5));
What is the result?
OptionsMultipleChoice
Given:
class Student {
String course, name, city;
public Student (String name, String course, String city) {
this.course = course; this.name = name; this.city = city;
}
public String toString() {
return course + '':'' + name + '':'' + city;
}
public String getCourse() {return course;}
public String getName() {return name;}
public String getCity() {return city;}
and the code fragment:
List<Student> stds = Arrays.asList(
new Student (''Jessy'', ''Java ME'', ''Chicago''),
new Student (''Helen'', ''Java EE'', ''Houston''),
new Student (''Mark'', ''Java ME'', ''Chicago''));
stds.stream()
.collect(Collectors.groupingBy(Student::getCourse))
.forEach(src, res) -> System.out.println(res));
What is the result?
OptionsMultipleChoice
Given the code fragments:
class Employee {
Optional<Address> address;
Employee (Optional<Address> address) {
this.address = address;
}
public Optional<Address> getAddress() { return address; }
}
class Address {
String city = ''New York'';
public String getCity { return city: }
public String toString() {
return city;
}
}
and
Address address = new Address;
Optional<Address> addrs1 = Optional.ofNullable (address);
Employee e1 = new Employee (addrs1);
String eAddress = (addrs1.isPresent()) ? addrs1.get().getCity() : ''City Not
available'';
System.out.println(eAddress);
What is the result?
OptionsMultipleChoice
Given the code fragment:
public void recDelete (String dirName) throws IOException {
File [ ] listOfFiles = new File (dirName) .listFiles();
if (listOfFiles ! = null && listOfFiles.length >0) {
for (File aFile : listOfFiles) {
if (!aFile.isDirectory ()) {
if (aFile.getName ().endsWith (''.class''))
aFile.delete ();
}
}
}
}
Assume that Projects contains subdirectories that contain .class files and is passed as an argument to the recDelete () method when it is invoked.
What is the result?
OptionsMultipleChoice
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?
OptionsMultipleChoice
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.getString(1));
16.System.out.println(''Description:'' + rs.getString(2));
17.System.out.println(''Price:'' + rs.getString(3));
18. System.out.println(Quantity:'' + rs.getString(4));
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?
OptionsMultipleChoice
Given the code fragments:
class Caller implements Callable<String> {
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?
OptionsMultipleChoice
Given:
class Vehicle implements Comparable<Vehicle>{
int vno;
String name;
public Vehicle (int vno, String name) {
this.vno = vno,;
this.name = name;
}
public String toString () {
return vno + '':'' + name;
}
public int compareTo(Vehicle o) {
return this.name.compareTo(o.name);
}
and this code fragment:
Set<Vehicle> vehicles = new TreeSet <> ();
vehicles.add(new Vehicle (10123, ''Ford''));
vehicles.add(new Vehicle (10124, ''BMW''));
System.out.println(vehicles);
What is the result?
OptionsMultipleChoice
Given:
public class Counter {
public static void main (String[ ] args) {
int a = 10;
int b = -1;
assert (b >=1) : ''Invalid Denominator'';
int = a / b;
System.out.println (c);
}
}
What is the result of running the code with the --da option?
OptionsMultipleChoice
Which statement is true about the single abstract method of the java.util.function.Predicate interface?
Options