Question 1

Given that data.txt and alldata.txt are accessible, and the code fragment:

What is required at line n1 to enable the code to overwrite alldata.txt with data.txt?
  • Question 2

    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) 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?
  • Question 3

    Given the code fragments:

    What is the result?
  • Question 4

    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 5

    Given:
    interface Rideable {Car getCar (String name); }
    class Car {
    private String name;
    public Car (String name) {
    this.name = name;
    }
    }
    Which code fragment creates an instance of Car?