Given the Greetings.properties file, containing:
and given:
What is the result?
Given that these files exist and are accessible:
and given the code fragment:
Which code fragment can be inserted at line n1 to enable the code to print only /company/emp?
Given the code fragments:
4. void doStuff() throws ArithmeticException, NumberFormatException, Exception {
5. if (Math.random() >-1 throw new Exception (“Try againâ€);
6. }
and
24. try {
25. doStuff ( ):
26. } catch (ArithmeticException | NumberFormatException | Exception e) {
27. System.out.println (e.getMessage()); }
28. catch (Exception e) {
29. System.out.println (e.getMessage()); }
30. }
Which modification enables the code to print Try again?
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:
List
DoubleFunction funD = d –> d + 100.0;
doubles.stream (). forEach (funD); // line n1
doubles.stream(). forEach(e –> System.out.println(e)); // line n2
What is the result?
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 –ea option?
Given:
IntStream stream = IntStream.of (1,2,3);
IntFunction
IntStream newStream = stream.map(inFu.apply(10));//line n2
newStream.forEach(System.out::print);
Which modification enables the code fragment to compile?
Given the code fragments:
class ThreadRunner implements Runnable {
public void run () { System.out.print (“Runnableâ€) ; }
}
class ThreadCaller implements Callable {
Public String call () throws Exception {return “Callableâ€; )
}
and
ExecutorService es = Executors.newCachedThreadPool ();
Runnable r1 = new ThreadRunner ();
Callable c1 = new ThreadCaller ();
// line n1
es.shutdown();
Which code fragment can be inserted at line n1 to start r1 and c1 threads?
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?
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:
public enum USCurrency {
PENNY (1),
NICKLE(5),
DIME (10),
QUARTER(25);
private int value;
public USCurrency(int value) {
this.value = value;
}
public int getValue() {return value;}
}
public class Coin {
public static void main (String[] args) {
USCurrency usCoin =new USCurrency.DIME;
System.out.println(usCoin.getValue()):
}
}
Which two modifications enable the given code to compile? (Choose two.)
Given:
and the code fragment:
Which definition of the ColorSorter class sorts the blocks list?
Given:
class Worker extends Thread {
CyclicBarrier cb;
public Worker(CyclicBarrier cb) { this.cb = cb; }
public void run () {
try {
cb.await();
System.out.println(“Worker…â€);
} catch (Exception ex) { }
}
}
class Master implements Runnable { //line n1
public void run () {
System.out.println(“Master…â€);
}
}
and the code fragment:
Master master = new Master();
//line n2
Worker worker = new Worker(cb);
worker.start();
You have been asked to ensure that the run methods of both the Worker and Master classes are executed.
Which modification meets the requirement?
Given:
and the code fragment:
The threads t1 and t2 execute asynchronously and possibly prints ABCA or AACB.
You have been asked to modify the code to make the threads execute synchronously and prints ABC.
Which modification meets the requirement?
Given:
interface Doable {
public void doSomething (String s);
}
Which two class definitions compile? (Choose two.)
Given:
public class product {
int id; int price;
public Product (int id, int price) {
this.id = id;
this.price = price;
}
public String toString() { return id + “:†+ price; }
}
and the code fragment:
List
new Product (2, 30),
new Product (2, 30));
Product p = products.stream().reduce(new Product (4, 0), (p1, p2) -> {
p1.price+=p2.price;
return new Product (p1.id, p1.price);});
products.add(p);
products.stream().parallel()
.reduce((p1, p2) - > p1.price > p2.price ? p1 : p2)
.ifPresent(System.out: :println);
What is the result?
Given the definition of the Vehicle class:
Class Vehhicle {
int distance;//line n1
Vehicle (int x) {
this distance = x;
}
public void increSpeed(int time) {//line n2
int timeTravel = time;//line n3
class Car {
int value = 0;
public void speed () {
value = distance /timeTravel;
System.out.println (“Velocity with new speedâ€+value+â€kmphâ€);
}
}
new Car().speed();
}
}
and this code fragment:
Vehicle v = new Vehicle (100);
v.increSpeed(60);
What is the result?
Given:
class Vehicle {
int vno;
String name;
public Vehicle (int vno, String name) {
this.vno = vno,;
this.name = name;
}
public String toString () {
return vno + “:†+ name;
}
}
and this code fragment:
Set
vehicles.add(new Vehicle (10123, “Fordâ€));
vehicles.add(new Vehicle (10124, “BMWâ€));
System.out.println(vehicles);
What is the result?
Given:
public final class IceCream {
public void prepare() {}
}
public class Cake {
public final void bake(int min, int temp) {}
public void mix() {}
}
public class Shop {
private Cake c = new Cake ();
private final double discount = 0.25;
public void makeReady () { c.bake(10, 120); }
}
public class Bread extends Cake {
public void bake(int minutes, int temperature) {}
public void addToppings() {}
}
Which statement is true?
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?