Given that course.txt is accessible and contains:
Course : : Java
and given the code fragment:
public static void main (String[ ] args) {
int i;
char c;
try (FileInputStream fis = new FileInputStream (“course.txt”);
InputStreamReader isr = new InputStreamReader(fis);) {
while (!isr.close()) { //line n1
isr.skip(2);
i = isr.read ();
c = (char) i;
System.out.print(c);
}
} catch (Exception e) {
e.printStackTrace();
}
}
What is the result?
Given the code fragment:
Stream
files.forEach (fName -> {//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?
Given that course.txt is accessible and contains:
Course : : Java
and given the code fragment:
public static void main (String[ ] args) {
int i;
char c;
try (FileInputStream fis = new FileInputStream (“course.txt”);
InputStreamReader isr = new InputStreamReader(fis);) {
while (isr.ready()) { //line n1
isr.skip(2);
i = isr.read ();
c = (char) i;
System.out.print(c);
}
} catch (Exception e) {
e.printStackTrace();
}
}
What is the result?
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?
Given the code fragment:
public class Foo {
public static void main (String [ ] args) {
Map
unsortMap.put (10, “z”);
unsortMap.put (5, “b”);
unsortMap.put (1, “d”);
unsortMap.put (7, “e”);
unsortMap.put (50, “j”);
Map
Comparator
@Override public int compare (Integer o1, Integer o2) {return o2.compareTo
(o2); } } );
treeMap.putAll (unsortMap);
for (Map.Entry
System.out.print (entry.getValue () + “ “);
}
}
}
What is the result?
Given the code fragment:
class CallerThread implements Callable
String str;
public CallerThread(String s) {this.str=s;}
public String call() throws Exception {
return str.concat(“Call”);
}
}
and
public static void main (String[] args) throws InterruptedException, ExecutionException
{
ExecutorService es = Executors.newFixedThreadPool(4); //line n1
Future f1 = es.submit (newCallerThread(“Call”));
String str = f1.get().toString();
System.out.println(str);
}
Which statement is true?
You have been asked to create a ResourceBundle which uses a properties file to localize an application.
Which code example specifies valid keys of menu1 and menu2 with values of File Menu and View Menu?
Given:
class Bird {
public void fly () { System.out.print(“Can fly”); }
}
class Penguin extends Bird {
public void fly () { System.out.print(“Cannot fly”); }
}
and the code fragment:
class Birdie {
public static void main (String [ ] args) {
fly( ( ) -> new Bird ( ));
fly (Penguin : : new);
}
/* line n1 */
}
Which code fragment, when inserted at line n1, enables the Birdie class to compile?
Given the code fragment:
and the information:
What is the result?
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
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?
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?
Given:
public class Customer {
private String fName;
private String lName;
private static int count;
public customer (String first, String last) {fName = first, lName = last;
++count;}
static { count = 0; }
public static int getCount() {return count; }
}
public class App {
public static void main (String [] args) {
Customer c1 = new Customer(“Larry”, “Smith”);
Customer c2 = new Customer(“Pedro”, “Gonzales”);
Customer c3 = new Customer(“Penny”, “Jones”);
Customer c4 = new Customer(“Lars”, “Svenson”);
c4 = null;
c3 = c2;
System.out.println (Customer.getCount());
}
}
What is the result?
Which two reasons should you use interfaces instead of abstract classes? (Choose two.)
Given the code fragment:
Which code fragment, when inserted at line n1, ensures false is printed?
Given the content:
and given the code fragment:
Which two code fragments, when inserted at line 1 independently, enable the code to print “Wie geht’s?”
Given the code fragment:
Which should be inserted into line n1 to print Average = 2.5?