Given the code fragment:
Which code fragment, when inserted at line n1, enables the code to print /First.txt?
Given the code fragment:
BiFunction
//line n2
System.out.println(val.apply(10, 10.5));
What is the result?
Given:
public class Test
private T t;
public T get () {
return t;
}
public void set (T t) {
this.t = t;
}
public static void main (String args [ ] ) {
Test
Test type 1 = new Test ();//line n1
type.set(“Java”);
type1.set(100);//line n2
System.out.print(type.get() + “ “ + type1.get());
}
}
What is the result?
Given:
public interface Moveable
public default void walk (Integer distance) {System.out.println(“Walking”);)
public void run(Integer distance);
}
Which statement is true?
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 the code fragment:
public void recDelete (String dirName) throws IOException {
File [ ] listOfFiles = new File (dirName) .listFiles();
if (listOfFiles ! = null && listOfFiles.length >0) {
for (File aFile : listOfFiles) {
if (aFile.isDirectory ()) {
recDelete (aFile.getAbsolutePath ());
} else {
if (aFile.getName ().endsWith (“.class”))
aFile.delete ();
}
}
}
}
Assume that Projects contains subdirectories that contain .class files and is passed as an argument to the recDelete () method when it is invoked.
What is the result?
Given the code fragment:
List
Predicate
System.out.println(“Searching…”);
return n.contains(“red”);
};
colors.stream()
.filter(c -> c.length() >= 3)
.allMatch(test);
What is the result?
Given the code fragment:
9. Connection conn = DriveManager.getConnection(dbURL, userName, passWord);
10. String query = “SELECT id FROM Employee”;
11. try (Statement stmt = conn.createStatement()) {
12. ResultSet rs = stmt.executeQuery(query);
13.stmt.executeQuery(“SELECT id FROM Customer”);
14. while (rs.next()) {
15. //process the results
16.System.out.println(“Employee ID: “+ rs.getInt(“id”));
17.}
18. } catch (Exception e) {
19. System.out.println (“Error”);
20. }
Assume that:
The required database driver is configured in the classpath.
The appropriate database is accessible with the dbURL, userName, and passWord exists.
The Employee and Customer tables are available and each table has id column with a few records and the SQL queries are valid.
What is the result of compiling and executing this code fragment?
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:
Which two interfaces can you use to create lambda expressions? (Choose two.)
Which two statements are true about synchronization and locks? (Choose two.)
Given:
class Book {
int id;
String name;
public Book (int id, String name) {
this.id = id;
this.name = name;
}
public boolean equals (Object obj) { //line n1
boolean output = false;
Book b = (Book) obj;
if (this.id = = b.id) {
output = true;
}
return output;
}
}
and the code fragment:
Book b1 = new Book (101, “Java Programing”);
Book b2 = new Book (102, “Java Programing”);
System.out.println (b1.equals(b2)); //line n2
Which statement is true?
Given the code fragments:
and
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 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?
Given:
What is the result?
Given the records from the STUDENT table:
Given the code fragment:
Assume that the URL, username, and password are valid.
What is the result?
Given the code fragments:
interface CourseFilter extends Predicate
public default boolean test (String str) {
return str.equals (“Java”);
}
}
and
List
Predicate
Predicate cf2 = new CourseFilter() { //line n1
public boolean test (String s) {
return s.contains (“Java”);
}
};
long c = strs.stream()
.filter(cf1)
.filter(cf2//line n2
.count();
System.out.println(c);
What is the result?
Given:
What is the result?
Given:
and the code fragment:
What is the result?
Given the code fragment:
List
Predicate
int i = 0;
boolean result = s.contains (“pen”);
System.out.print(i++) + “:”);
return result;
};
str.stream()
.filter(test)
.findFirst()
.ifPresent(System.out ::print);
What is the result?
Given the code fragment:
Path p1 = Paths.get(“/Pics/MyPic.jpeg”);
System.out.println (p1.getNameCount() +
“:” + p1.getName(1) +
“:” + p1.getFileName());
Assume that the Pics directory does NOT exist.
What is the result?
Which two code blocks correctly initialize a Locale variable? (Choose two.)
Given:
class UserException extends Exception { }
class AgeOutOfLimitException extends UserException { }
and the code fragment:
class App {
public void doRegister(String name, int age)
throws UserException, AgeOutOfLimitException {
if (name.length () < 6) {
throw new UserException ();
} else if (age >= 60) {
throw new AgeOutOfLimitException ();
} else {
System.out.println(“User is registered.”);
}
}
public static void main(String[ ] args) throws UserException {
App t = new App ();
t.doRegister(“Mathew”, 60);
}
}
What is the result?
Given the code fragment:
BiFunction
System.out.println(val.apply(10, 10.5));
What is the result?
Given the code fragment:
What is the result?
Given:
Which option fails?
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:
Path path1 = Paths.get(“/app/./sys/”);
Path res1 = path1.resolve(“log”);
Path path2 = Paths.get(“/server/exe/”);
Path res1 = path1.resolve(“/readme/”);
System.out.println(res1);
System.out.println(res2);
What is the result?