Java SE 8 Programmer II v1.0 (1z0-809)

Page:    1 / 14   
Total 207 questions

Given:
public interface Moveable<Integer> {
public default void walk (Integer distance) {System.out.println("Walking");) public void run(Integer distance);
}
Which statement is true?

  • A. Moveable can be used as below: Moveable<Integer> animal = n - > System.out.println("Running" + n); animal.run(100); animal.walk(20);
  • B. Moveable can be used as below: Moveable<Integer> animal = n - > n + 10; animal.run(100); animal.walk(20);
  • C. Moveable can be used as below: Moveable animal = (Integer n1, Integer n2) -> n+ n2; animal.run(100); animal.walk(20);
  • D. Movable cannot be used in a lambda expression.


Answer : A

Which two code blocks correctly initialize a Locale variable? (Choose two.)

  • A. Locale loc1 = "UK";
  • B. Locale loc2 = Locale.getInstance("ru");
  • C. Locale loc3 = Locale.getLocaleFactory("RU");
  • D. Locale loc4 = Locale.UK;
  • E. Locale loc5 = new Locale ("ru", "RU");


Answer : DE

Given:
class FuelNotAvailException extends Exception { }
class Vehicle {
void ride() throws FuelNotAvailException { //line n1
System.out.println("Happy Journey!");
}
}
class SolarVehicle extends Vehicle {
public void ride () throws Exception { //line n2
super ride ();
}
}
and the code fragment:
public static void main (String[] args) throws FuelNotAvailException, Exception {
Vehicle v = new SolarVehicle ();
v.ride();
}
Which modification enables the code fragment to print Happy Journey!?

  • A. Replace line n1 with public void ride() throws FuelNotAvailException {
  • B. Replace line n1 with protected void ride() throws Exception {
  • C. Replace line n2 with void ride() throws Exception {
  • D. Replace line n2 with private void ride() throws FuelNotAvailException {


Answer : B

Given the definition of the Emp class:
public class Emp
private String eName;
private Integer eAge;

Emp(String eN, Integer eA) {
this.eName = eN;
this.eAge = eA;
}
public Integer getEAge () {return eAge;}
public String getEName () {return eName;}
}
and code fragment:
List<Emp>li = Arrays.asList(new Emp("Sam", 20), New Emp("John", 60), New Emp("Jim", 51));
Predicate<Emp> agVal = s -> s.getEAge() > 50; //line n1 li = li.stream().filter(agVal).collect(Collectors.toList());
Stream<String> names = li.stream()map.(Emp::getEName); //line n2 names.forEach(n -> System.out.print(n + " "));
What is the result?

  • A. Sam John Jim
  • B. John Jim
  • C. A compilation error occurs at line n1.
  • D. A compilation error occurs at line n2.


Answer : B

For which three objects must a vendor provide implementations in its JDBC driver? (Choose three.)

  • A. Time
  • B. Date
  • C. Statement
  • D. ResultSet
  • E. Connection
  • F. SQLException
  • G. DriverManager


Answer : CDE

Explanation:
Database vendors support JDBC through the JDBC driver interface or through the ODBC connection. Each driver must provide implementations of java.sql.Connection, java.sql.Statement, java.sql.PreparedStatement, java.sql.CallableStatement, and java.sql.Re sultSet. They must also implement the java.sql.Driver interface for use by the generic java.sql.DriverManager interface.

Given the code fragment:
LocalDate valentinesDay =LocalDate.of(2015, Month.FEBRUARY, 14);
LocalDate nextYear = valentinesDay.plusYears(1);
nextYear.plusDays(15); //line n1
System.out.println(nextYear);
What is the result?

  • A. 2016-02-14
  • B. A DateTimeException is thrown.
  • C. 2016-02-29
  • D. A compilation error occurs at line n1.


Answer : A

Given the code fragment:
BiFunction<Integer, Double, Integer> val = (t1, t2) -> t1 + t2; //line n1
System.out.println(val.apply(10, 10.5));
What is the result?

  • A. 20
  • B. 20.5
  • C. A compilation error occurs at line n1.
  • D. A compilation error occurs at line n2.


Answer : C

Which statement is true about java.time.Duration?

  • A. It tracks time zones.
  • B. It preserves daylight saving time.
  • C. It defines time-based values.
  • D. It defines date-based values.


Answer : C

Reference:
http://tutorials.jenkov.com/java-date-time/duration.html#accessing-the-time-of-a-duration

Given the code fragment:
UnaryOperator<Integer> uo1 = s -> s*2; line n1
List<Double> loanValues = Arrays.asList(1000.0, 2000.0);
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.


Answer : D

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?

  • A. <key name = "˜menu1">File Menu</key> <key name = "˜menu2">View Menu</key>
  • B. <key>menu1</key><value>File Menu</value> <key>menu2</key><value>View Menu</value>
  • C. menu1, File Menu, menu2, View Menu Menu
  • D. menu1 = File Menu menu2 = View Menu


Answer : D

Given the records from the Employee table:

and given the code fragment: try {
Connection conn = DriverManager.getConnection (URL, userName, passWord);
Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
st.execute("SELECT*FROM Employee");
ResultSet rs = st.getResultSet();
while (rs.next()) {
if (rs.getInt(1) ==112) {
rs.updateString(2, "Jack");
}
}
rs.absolute(2);
System.out.println(rs.getInt(1) + " " + rs.getString(2));
} catch (SQLException ex) {
System.out.println("Exception is raised");
}
Assume that:
The required database driver is configured in the classpath.
The appropriate database accessible with the URL, userName, and passWord exists.
What is the result?

  • A. The Employee table is updated with the row: 112 Jack and the program prints: 112 Jerry
  • B. The Employee table is updated with the row: 112 Jack and the program prints: 112 Jack
  • C. The Employee table is not updated and the program prints: 112 Jerry
  • D. The program prints Exception is raised.


Answer : C

Given:
class RateOfInterest {
public static void main (String[] args) {
int rateOfInterest = 0;
String accountType = "LOAN";
switch (accountType) {
case "RD";
rateOfInterest = 5;
break;
case "FD";
rateOfInterest = 10;
break;
default:
assert false: "No interest for this account"; //line n1
}
System.out.println ("Rate of interest:" + rateOfInterest);
}
}
and the command:
java ""ea RateOfInterest
What is the result?

  • A. Rate of interest: 0
  • B. An AssertionError is thrown.
  • C. No interest for this account
  • D. A compilation error occurs at line n1.


Answer : B

Given the code fragment:
class CallerThread implements Callable<String> {
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?

  • A. The program prints Call Call and terminates.
  • B. The program prints Call Call and does not terminate.
  • C. A compilation error occurs at line n1.
  • D. An ExecutionException is thrown at run time.


Answer : B

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 Projects directory exists and contains a list of files.
What is the result?

  • A. The program throws a runtime exception at line n2.
  • B. The program prints files names concurrently.
  • C. The program prints files names sequentially.
  • D. A compilation error occurs at line n1.


Answer : B

Given:
class CheckClass {
public static int checkValue (String s1, String s2) {
return s1 length() "" s2.length();
}
}
and the code fragment:
String[] strArray = new String [] {"Tiger", "Rat", "Cat", "Lion"};
//line n1
for (String s : strArray) {
System.out.print (s + " ");
}
Which code fragment should be inserted at line n1 to enable the code to print Rat Cat Lion Tiger?

  • A. Arrays.sort(strArray, CheckClass : : checkValue);
  • B. Arrays.sort(strArray, (CheckClass : : new) : : checkValue);
  • C. Arrays.sort(strArray, (CheckClass : : new).checkValue);
  • D. Arrays.sort(strArray, CheckClass : : new : : checkValue);


Answer : A

Page:    1 / 14   
Total 207 questions