Given:
and the code fragment:
What is the result?
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 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?
Given that these files exist and are accessible:
/sports/info.txt
/sports/cricket/players.txt
/sports/cricket/data/ODI.txt
and given the code fragment:
int maxDepth =2;
Stream
maxDepth,
(p, a) -> p.getFileName().toString().endsWith (“txt”),
FileVisitOption.FOLLOW_LINKS);
Long fCount = paths.count();
System.out.println(fCount);
Assuming that there are NO soft-link/symbolic links to any of the files in the directory structure, 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 the content of the employee.txt file:
Every worker is a master.
Given that the employee.txt file is accessible and the file allemp.txt does NOT exist, and the code fragment:
What is the result?
Given the code fragment:
BiFunction
//line n2
System.out.println(val.apply(10, 10.5));
What is the result?
Given the code fragment:
Stream> iStr= Stream.of (
Arrays.asList (“1”, “John”),
Arrays.asList (“2”, null)0;
Stream<
nInSt.forEach (System.out :: print);
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 the code fragment:
List
values.stream ()
.map(n -> n*2)//line n1
.peek(System.out::print)//line n2
.count();
What is the result?
Given the code fragment:
What is the result?
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.getInt(“Id”));
16.System.out.println(“Description:“ + rs.getString(“Descrip”));
17.System.out.println(“Price:“ + rs.getDouble(“Price”));
18. System.out.println(Quantity:“ + rs.getInt(“Quantity”));
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 code fragments:
and
What is the result?
Given the code fragment:
and the information:
What is the result?
Given:
final class Folder {//line n1
//line n2
public void open () {
System.out.print(“Open”);
}
}
public class Test {
public static void main (String [] args) throws Exception {
try (Folder f = new Folder()) {
f.open();
}
}
}
Which two modifications enable the code to print Open Close? (Choose two.)
Given the code fragment:
List
List
//line n1
Which code fragment, when inserted at line n1, prints 10 20 15 30?
Given the structure of the Student table:
Student (id INTEGER, name VARCHAR)
Given the records from the STUDENT table:
Given the code fragment:
Assume that:
What is the result?
Given the code fragments:
class MyThread implements Runnable {
private static AtomicInteger count = new AtomicInteger (0);
public void run () {
int x = count.incrementAndGet();
System.out.print (x+” “);
}
}
and
Thread thread1 = new Thread(new MyThread());
Thread thread2 = new Thread(new MyThread());
Thread thread3 = new Thread(new MyThread());
Thread [] ta = {thread1, thread2, thread3};
for (int x= 0; x < 3; x++) {
ta[x].start();
}
Which statement is true?
Given the code fragments:
and
What is the result?
Given the code fragment:
Which modification enables the code to print Price 5 New Price 4?
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 the code fragment:
Which code fragment, when inserted at line n1, ensures false is printed?
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 structure of the STUDENT table:
Student (id INTEGER, name VARCHAR)
Given:
public class Test {
static Connection newConnection =null;
public static Connection get DBConnection () throws SQLException {
try (Connection con = DriveManager.getConnection(URL, username, password)) {
newConnection = con;
}
return newConnection;
}
public static void main (String [] args) throws SQLException {
get DBConnection ();
Statement st = newConnection.createStatement();
st.executeUpdate(“INSERT INTO student VALUES (102, ‘Kelvin’)”);
}
}
Assume that:
The required database driver is configured in the classpath.
The appropriate database is accessible with the URL, userName, and passWord exists.
The SQL query is valid.
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:
and the code fragment:
What is the result?
Given the code fragment:
UnaryOperator
List
loanValues.stream()
.filter(lv -> lv >= 1500)
.map(lv -> uo1.apply(lv))
.forEach(s -> System.out.print(s + “ “));
What is the result?
Given:
From what threading problem does the program suffer?
Given the definition of the Book class:
Which statement is true about the Book class?