Question 101

Given:

What is the result?
  • Question 102

    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 103

    Given:
    class Sum extends RecursiveAction { //line n1
    static final int THRESHOLD_SIZE = 3;
    int stIndex, lstIndex;
    int [ ] data;
    public Sum (int [ ]data, int start, int end) {
    this.data = data;
    this stIndex = start;
    this. lstIndex = end;
    }
    protected void compute ( ) {
    int sum = 0;
    if (lstIndex - stIndex <= THRESHOLD_SIZE) {
    for (int i = stIndex; i < lstIndex; i++) {
    sum += data [i];
    }
    System.out.println(sum);
    } else {
    new Sum (data, stIndex + THRESHOLD_SIZE, lstIndex).fork( );
    new Sum (data, stIndex,
    Math.min (lstIndex, stIndex + THRESHOLD_SIZE)
    ).compute ();
    }
    }
    }
    and the code fragment:
    ForkJoinPool fjPool = new ForkJoinPool ( ); int data [ ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} fjPool.invoke (new Sum (data, 0, data.length));
    and given that the sum of all integers from 1 to 10 is 55. Which statement is true?
  • Question 104

    Given the Greetings.properties file, containing:

    and given:

    What is the result?
  • Question 105

    Given:

    What is the result?