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?
Which two reasons should you use interfaces instead of abstract classes? (Choose two.)
Given:
class CheckClass {
public static int checkValue (String s1, String s2) {
return s1 length() – s2.length();
}
}
and the code fragment:
String[] strArray = new String [] {“Tiger”, “Rat”, “Cat”, “Lion”}
//line n1
for (String s : strArray) {
System.out.print (s + “ “);
}
Which code fragment should be inserted at line n1 to enable the code to print Rat Cat Lion Tiger?
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:
Path path1 = Paths.get(“/app/./sys/”);
Path res1 = path1.resolve(“log”);
Path path2 = Paths.get(“/server/exe/”);
Path res1 = path2.resolve(“/readme/”);
System.out.println(res1);
System.out.println(res2);
What is the result?
Given:
and the code fragment:
Which two code fragments, when inserted at line n1 independently, enable the code to print TruckCarBike?
Given:
class Vehicle implements Comparable
int vno;
String name;
public Vehicle (int vno, String name) {
this.vno = vno,;
this.name = name;
}
public String toString () {
return vno + “:” + name;
}
public int compareTo(Vehicle o) {
return this.name.compareTo(o.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:
BiFunction
System.out.println(val.apply(10, 10.5));
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:
class TechName {
String techName;
TechName (String techName) {
this.techName=techName;
}
}
and
List
new TechName(“Java-“),
new TechName(“Oracle DB-“),
new TechName(“J2EE-“)
);
Stream
//line n1
Which should be inserted at line n1 to print Java-Oracle DB-J2EE-?
Given the code fragment:
List
empDetails.stream()
.filter(s-> s.contains(“r”))
.sorted()
.forEach(System.out::println); //line n1
What is the result?
Given the code fragment:
Map
books.put (1007, “A”);
books.put (1002, “C”);
books.put (1001, “B”);
books.put (1003, “B”);
System.out.println (books);
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.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:
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?
Given the code fragment:
List
“200, Mary, AdminServices”,
“101, Peter, HR”);
empDetails.stream()
.filter(s-> s.contains(“1”))
.sorted()
.forEach(System.out::println); //line n1
What is the result?
Given the code fragment:
Map
books.put (1007, “A”);
books.put (1002, “C”);
books.put (1003, “B”);
books.put (1003, “B”);
System.out.println (books);
What is the result?
Given the code fragment:
UnaryOperator
List
loanValues.stream()
.filter(lv -> lv >= 1500)
.map(lv -> uo1.apply(lv))//line n2
.forEach(s -> System.out.print(s + “ “));
What is the result?
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?
You want to create a singleton class by using the Singleton design pattern.
Which two statements enforce the singleton nature of the design? (Choose two.)
Given that version.txt is accessible and contains:
1234567890
and given 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:
1. abstract class Shape {
2. Shape ( ) { System.out.println (“Shape”); }
3. protected void area ( ) { System.out.println (“Shape”); }
4. }
5.
6. class Square extends Shape {
7. int side;
8. Square int side {
9./* insert code here */
10. this.side = side;
11. }
12. public void area ( ) { System.out.println (“Square”); }
13. }
14. class Rectangle extends Square {
15. int len, br;
16. Rectangle (int x, int y) {
17. /* insert code here */
18. len = x, br = y;
19. }
20. void area ( ) { System.out.println (“Rectangle”); }
21. }
Which two modifications enable the code to compile? (Choose two.)
Given the code fragment:
Which modification enables the code to print Price 5 New Price 4?
Given the code fragment:
Which statement can be inserted into line n1 to print 1,2; 1,10; 2,20;?
Given the code fragment:
Which should be inserted into line n1 to print Average = 2.5?
Given the code fragments:
and
Which two modifications enable to sort the elements of the emps list? (Choose two.)
Given:
Which two interfaces can you use to create lambda expressions? (Choose two.)
Given:
Book.java:
public class Book {
private String read(String bname) { return “Read” + bname }
}
EBook.java:
public class EBook extends Book {
public class String read (String url) { return “View” + url }
}
Test.java:
public class Test {
public static void main (String[] args) {
Book b1 = new Book();
b1.read(“Java Programing”);
Book b2 = new EBook();
b2.read(“http://ebook.com/ebook”);
}
}
What is the result?
For which three objects must a vendor provide implementations in its JDBC driver? (Choose three.)
Given that course.txt is accessible and contains:
Course : : Java
and given the code fragment:
public static void main (String[ ] args) {
int i;
char c;
try (FileInputStream fis = new FileInputStream (“course.txt”);
InputStreamReader isr = new InputStreamReader(fis);) {
while (isr.ready()) { //line n1
isr.skip(2);
i = isr.read ();
c = (char) i;
System.out.print(c);
}
} catch (Exception e) {
e.printStackTrace();
}
}
What is the result?
Given the code fragment:
Assume that the value of now is 6:30 in the morning.
What is the result?
Given the code fragment:
Which code fragment, when inserted at line n1, ensures false is printed?
Given:
public class Emp {
String fName;
String lName;
public Emp (String fn, String ln) {
fName = fn;
lName = ln;
}
public String getfName() { return fName; }
public String getlName() { return lName; }
}
and the code fragment:
List
new Emp (“John”, “Smith”),
new Emp (“Peter”, “Sam”),
new Emp (“Thomas”, “Wale”));
emp.stream()
//line n1
.collect(Collectors.toList());
Which code fragment, when inserted at line n1, sorts the employees list in descending order of fName and then ascending order of lName?
Given the code fragment:
ZonedDateTime depart = ZonedDateTime.of(2015, 1, 15, 1, 0, 0, 0, ZoneID.of(“UTC-7”));
ZonedDateTime arrive = ZonedDateTime.of(2015, 1, 15, 9, 0, 0, 0, ZoneID.of(“UTC-5”));
long hrs = ChronoUnit.HOURS.between(depart, arrive); //line n1
System.out.println(“Travel time is” + hrs + “hours”);
What is the result?
Given the code fragment:
Which code fragment, when inserted at line 7, enables printing 100?
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 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 the code fragment:
Stream
files.forEach (fName -> {//line n1
try {
Path aPath = fName.toAbsolutePath();//line n2
System.out.println(fName + “:”
+ Files.readAttributes(aPath, Basic.File.Attributes.class).creationTime
());
} catch (IOException ex) {
ex.printStackTrace();
});
What is the result?
Given the definition of the Country class:
public class country {
public enum Continent {ASIA, EUROPE}
String name;
Continent region;
public Country (String na, Continent reg) {
name = na, region = reg;
}
public String getName () {return name;}
public Continent getRegion () {return region;}
}
and the code fragment:
List
new Country (“Japan”, Country.Continent.ASIA),
new Country (“Italy”, Country.Continent.EUROPE),
new Country (“Germany”, Country.Continent.EUROPE));
Map
.collect(Collectors.groupingBy (Country ::getRegion,
Collectors.mapping(Country::getName, Collectors.toList()))));
System.out.println(regionNames);
What is the output?