Summer Special - Limited Time 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: top65certs

Free and Premium Oracle 1z0-809 Dumps Questions Answers

Page: 1 / 16
Total 208 questions

Java SE 8 Programmer II Questions and Answers

Question 1

Given the code fragment:

ZonedDateTime depart = ZonedDateTime.of(2015, 1, 15, 3, 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?

Options:

A.

Travel time is 4 hours

B.

Travel time is 6 hours

C.

Travel time is 8 hours

D.

An exception is thrown at line n1.

Buy Now
Question 2

Given the EMPLOYEE table;

Given the code fragment:

Assuming the database supports scrolling and updating, what is the result?

Options:

A.

The program throws a runtime exception at Line 1.

B.

A compilation error occurs.

C.

A new record is inserted and Employee Id: 102, Employee Name: Peter is displayed.

D.

A new record is inserted and Employee Id: 104, Employee Name: Michael is displayed.

Question 3

Given the code fragment:

List list1 = Arrays.asList(10, 20);

List list2 = Arrays.asList(15, 30);

//line n1

Which code fragment, when inserted at line n1, prints 10 20 15 30?

Options:

A.

Stream.of(list1, list2).flatMap(list -> list.stream()).forEach(s -> System.out.print(s + “ “));

B.

Stream.of(list1, list2).flatMap(list -> list.intStream()).forEach(s -> System.out.print(s + “ “));

C.

list1.stream().flatMap(list2.stream().flatMap(e1 -> e1.stream()).forEach(s -> System.out.println(s + “ “));

D.

Stream.of(list1, list2).flatMapToInt(list -> list.stream()).forEach(s -> System.out.print(s + “ “));

Question 4

Given the content of resources /Message.properties:

greet = Good Day!

Given the content of resources/Message_de_DE.properties:

greet = Guten Tag!

Given the code fragment from C:\src\App.java:

Options:

A.

A compilation error occurs. To ensure successful compilation, replace line n1 with:

ResourceBundle bundle = ResourceBundle.getBundle("/resources/Message.properties", locale);

B.

A java.util.MissingResourceException is thrown at run time.

C.

Good Day!

D.

Guten Tag!

Question 5

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 products = new ArrayList <> (Arrays.asList(new Product(1, 10),

new Product (2, 30),

new Product (3, 20));

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?

Options:

A.

4:60

B.

2:30

C.

4:602:303:201:10

D.

4:0

E.

The program prints nothing

Question 6

Given the records from the Employee table:

and given the code fragment:

try {

Connection conn = DriverManager.getConnection (URL, userName, passWord);

Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

st.execute(“SELECT*FROM Employee”);

ResultSet rs = st.getResultSet();

while (rs.next()) {

if (rs.getInt(1) ==112) {

rs.updateString(2, “Jack”);

}

}

rs.absolute(2);

System.out.println(rs.getInt(1) + “ “ + rs.getString(2));

} catch (SQLException ex) {

System.out.println(“Exception is raised”);

}

Assume that:

The required database driver is configured in the classpath.

The appropriate database accessible with the URL, userName, and passWord exists.

What is the result?

Options:

A.

The Employee table is updated with the row:112 Jackand the program prints:112 Jerry

B.

The Employee table is updated with the row:112 Jackand the program prints:112 Jack

C.

The Employee table is not updated and the program prints:112 Jerry

D.

The program prints Exception is raised.

Question 7

Given the code fragment:

LocalDate valentinesDay =LocalDate.of(2015, Month.FEBRUARY, 14);

LocalDate next15days = valentinesDay.plusDays (15);

LocalDate nextYear = next15days.plusYears(1); // line n1

System.out.println(nextYear);

What is the result?

Options:

A.

2016-03-01

B.

A DateTimeException is thrown.

C.

2016-02-29

D.

A compilation error occurs at line n1.

Question 8

Given:

and the code fragment:

Which modification enables the code fragment to print Speaker?

Options:

A.

Implement Predicate in the Product.ProductFilter class and replace line n2 with .filter (p -> p.ProductFilter.test (p))

B.

Replace line n1 with:public static boolean isAvailable (Product p) {

C.

Replace line n2 with:.filter (p -> p.ProductFilter: :isAvailable (p))

D.

Replace line n2 with:.filter (p -> Product: :ProductFilter: :isAvailable ())

Question 9

Given:

What is the result?

Options:

A.

The program prints nothing.

B.

A compile-time error occurs.

C.

Exception is thrown.

D.

MyException is thrown.

Question 10

Which statement is true about the single abstract method of the java.util.function.Function interface?

Options:

A.

It accepts one argument and returns void.

B.

It accepts one argument and returns boolean.

C.

It accepts one argument and always produces a result of the same type as the argument.

D.

It accepts an argument and produces a result of any data type.

Question 11

Given:

Which is refactored code with functional interfaces?

Options:

A.

B.

C.

D.

Question 12

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.)

Options:

A.

Replace line n1 with:class Folder implements AutoCloseable {

B.

Replace line n1 with:class Folder extends Closeable {

C.

Replace line n1 with:class Folder extends Exception {

D.

At line n2, insert:final void close () {System.out.print(“Close”);}

E.

At line n2, insert:public void close () throws IOException {System.out.print(“Close”);}

Question 13

Given the structure of the EHF and DEPT tables:

Given the code fragment:

What is the result?

Options:

A.

The code prints all of the records in the EM? table but not with the respective department names.

B.

The code prints all of the records in the EMP table along with the respective department names.

C.

The code throws a syntax error at ResultSet because the semicolon (:) is missing.

D.

The code prints only the first record of the EM? table.

Question 14

Given the code fragment:

Assume that the value of now is 6:30 in the morning.

What is the result?

Options:

A.

An exception is thrown at run time.

B.

0

C.

60

D.

1

Question 15

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.name.equals(b name))}

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?

Options:

A.

The program prints true.

B.

The program prints false.

C.

A compilation error occurs. To ensure successful compilation, replace line n1 with:boolean equals (Book obj) {

D.

A compilation error occurs. To ensure successful compilation, replace line n2 with:System.out.println (b1.equals((Object) b2));

Question 16

Given the code fragment:

List nL = Arrays.asList(“Jim”, “John”, “Jeff”);

Function funVal = s -> “Hello : “.concat(s);

nL.Stream()

.map(funVal)

.forEach(s-> System.out.print (s));

What is the result?

Options:

A.

Hello : Jim Hello : John Hello : Jeff

B.

Jim John Jeff

C.

The program prints nothing.

D.

A compilation error occurs.

Question 17

Given:

and the code fragment:

What is the result?

Options:

A.

[Java EE: Helen:Houston][Java ME: Jessy:Chicago, Java ME: Mark:Chicago]

B.

Java EEJava ME

C.

[Java ME: Jessy:Chicago, Java ME: Mark:Chicago][Java EE: Helen:Houston]

D.

A compilation error occurs.

Question 18

You have been asked to create a ResourceBundle which uses a properties file to localize an application.

Which code example specifies valid keys of menu1 and menu2 with values of File Menu and View Menu?

Options:

A.

File MenuView Menu

B.

menu1File Menumenu2View Menu

C.

menu1, File Menu, menu2, View Menu

D.

menu1 = File Menumenu2 = View Menu

Question 19

Given the code fragment:

What is the result?

Options:

A.

A compilation error occurs at line n2.

B.

3

C.

2

D.

A compilation error occurs at line n1.

Question 20

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?

Options:

A.

/app/sys/log/readme/server/exe

B.

/app/log/sys/server/exe/readme

C.

/app/./sys/log/readme

D.

/app/./sys/log/server/exe/readme

Question 21

and the code fragment?

What is the result?

Options:

A.

$15.00

B.

15 $

C.

USD 15.00

D.

USD $15

Question 22

Given the code fragment:

What is the result?

Options:

A.

DavidDavid[Susan, Allen]

B.

SusanSusan[Susan, Allen]

C.

SusanAllen[David]

D.

DavidAllen[Susan]

E.

SusanAllen[Susan, David]

Question 23

Given:

and the code fragment:

What is the result?

Options:

A.

A compilation error occurs at line n2.

B.

A compilation error occurs because the try block doesn’t have a catch or finally block.

C.

A compilation error occurs at line n1.

D.

The program compiles successfully.

Question 24

Given the code fragment:

What is the result?

Options:

A.

Val:20 Val:40 Val:60

B.

Val:10 Val:20 Val:30

C.

A compilation error occurs.

D.

Val: Val: Val:

Question 25

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?

Options:

A.

The program prints employee IDs.

B.

The program prints customer IDs.

C.

The program prints Error.

D.

compilation fails on line 13.

Question 26

Given the code fragment:

Which two code fragments, when inserted at line n1 independently, result in the output PEEK: Unix?

Options:

A.

.anyMatch ();

B.

.allMatch ();

C.

.findAny ();

D.

.noneMatch ();

E.

.findFirst ();

Question 27

Given the content:

and the code fragment:

What is the result?

Options:

A.

username = Entrez le nom d’utilisateurpassword = Entrez le mot de passe

B.

username = Enter User Namepassword = Enter Password

C.

A compilation error occurs.

D.

The program prints nothing.

Question 28

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?

Options:

A.

ur :: va

B.

ueJa

C.

The program prints nothing.

D.

A compilation error occurs at line n1.

Question 29

Given that data.txt and alldata.txt are accessible, and the code fragment:

What is required at line n1 to enable the code to overwrite alldata.txt with data.txt?

Options:

A.

br.close();

B.

bw.writeln();

C.

br.flush();

D.

bw.flush();

Question 30

Given:

and the code fragment:

What is the result?

Options:

A.

An exception is thrown at line n2.

B.

100

C.

A compilation error occurs because the try block is declared without a catch or finally block.

D.

A compilation error occurs at line n1.

Question 31

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.)

Options:

A.

Make the class static.

B.

Make the constructor private.

C.

Override equals() and hashCode() methods of the java.lang.Object class.

D.

Use a static reference to point to the single instance.

E.

Implement the Serializable interface.

Question 32

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?

Options:

A.

The program prints Status: true and two records are deleted from the Student table.

B.

The program prints Status: false and two records are deleted from the Student table.

C.

A SQLException is thrown at runtime.

D.

The program prints Status: false but the records from the Student table are not deleted.

Question 33

Given:

class FuelNotAvailException extends Exception { }

class Vehicle {

void ride() throws FuelNotAvailException {//line n1

System.out.println(“Happy Journey!”);

}

}

class SolarVehicle extends Vehicle {

public void ride () throws FuelNotAvailException {//line n2

super ride ();

}

}

and the code fragment:

public static void main (String[] args) throws Exception {

Vehicle v = new SolarVehicle ();

v.ride();

}

Which modification enables the code fragment to print Happy Journey!?

Options:

A.

Replace line n1 with public void ride() throws FuelNotAvailException {

B.

Replace line n1 with protected void ride() throws Exception {

C.

Replace line n2 with void ride() throws Exception {

D.

Replace line n2 with private void ride() throws FuelNotAvailException {

Question 34

Given:

public interface Moveable {

public default void walk (Integer distance) {System.out.println(“Walking”);)

public void run(Integer distance);

}

Which statement is true?

Options:

A.

Moveable can be used as below:Moveable animal = n - > System.out.println(“Running” + n);animal.run(100);animal.walk(20);

B.

Moveable can be used as below:Moveable animal = n - > n + 10;animal.run(100);animal.walk(20);

C.

Moveable can be used as below:Moveable animal = (Integer n) - > System.out.println(n);animal.run(100);Moveable.walk(20);

D.

Movable cannot be used in a lambda expression.

Question 35

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 () <= 60) {

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?

Options:

A.

User is registered.

B.

An AgeOutOfLimitException is thrown.

C.

A UserException is thrown.

D.

A compilation error occurs in the main method.

Question 36

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?

Options:

A.

Arrays.sort(strArray, CheckClass : : checkValue);

B.

Arrays.sort(strArray, (CheckClass : : new) : : checkValue);

C.

Arrays.sort(strArray, (CheckClass : : new).checkValue);

D.

Arrays.sort(strArray, CheckClass : : new : : checkValue);

Question 37

Given the information: The employee table has 10 records.

Given the code fragment:

What is the result?

Options:

A.

deletes the second row and prints the emp_id of the first row

B.

throws a runtime exception at Line n1

C.

deletes the first row and throws an exception at Line n2

D.

deletes the first row and prints the emp_id of the second row

Question 38

Which statement is true about the single abstract method of the java.util.function.Predicate interface?

Options:

A.

It accepts one argument and returns void.

B.

It accepts one argument and returns boolean.

C.

It accepts one argument and always produces a result of the same type as the argument.

D.

It accepts an argument and produces a result of any data type.

Question 39

The data.doc, data.txt and data.xml files are accessible and contain text.

Given the code fragment:

Stream paths = Stream.of (Paths. get(“data.doc”),

Paths. get(“data.txt”),

Paths. get(“data.xml”));

paths.filter(s-> s.toString().endWith(“txt”)).forEach(

s -> {

try {

Files.readAllLines(s)

.stream()

.forEach(System.out::println); //line n1

} catch (IOException e) {

System.out.println(“Exception”);

}

}

);

What is the result?

Options:

A.

The program prints the content of data.txt file.

B.

The program prints:Exception<>Exception

C.

A compilation error occurs at line n1.

D.

The program prints the content of the three files.

Question 40

Given the code fragment:

What is the result?

Options:

A.

4000 : 2000

B.

4000 : 1000

C.

1000 : 4000

D.

1000 : 2000

Question 41

Given:

and the command:

java Product 0

What is the result?

Options:

A.

An AssertionError is thrown.

B.

A compilation error occurs at line n1.

C.

New Price: 0.0

D.

A NumberFormatException is thrown at run time.

Question 42

Given the code fragments:

and

What is the result?

Options:

A.

null

B.

A compilation error occurs.

C.

DogCatMouse

D.

[Dog, Cat, Mouse]

Question 43

Given the code fragment:

Which statement can be inserted into line n1 to print 1,2; 1,10; 2,20;?

Options:

A.

BiConsumer c = (i, j) -> {System.out.print (i + “,” + j+ “; “);};

B.

BiFunction c = (i, j) –> {System.out.print (i + “,” + j+ “; “)};

C.

BiConsumer c = (i, j) –> {System.out.print (i + “,” + j+ “; “)};

D.

BiConsumer c = (i, j) –> {System.out.print (i + “,” + j+ “; “);};

Question 44

Given that version.txt is accessible and contains:

1234567890

and given the code fragment:

What is the result?

Options:

A.

121

B.

122

C.

135

D.

The program prints nothing.

Question 45

Given the code fragment:

Which should be inserted into line n1 to print Average = 2.5?

Options:

A.

IntStream str = Stream.of (1, 2, 3, 4);

B.

IntStream str = IntStream.of (1, 2, 3, 4);

C.

DoubleStream str = Stream.of (1.0, 2.0, 3.0, 4.0);

D.

Stream str = Stream.of (1, 2, 3, 4);

Question 46

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?

Options:

A.

The program executes successfully and the STUDENT table is updated with one record.

B.

The program executes successfully and the STUDENT table is NOT updated with any record.

C.

A SQLException is thrown as runtime.

D.

A NullPointerException is thrown as runtime.

Question 47

Given the code fragments:

and

What is the result?

Options:

A.

The program prints Run… and throws an exception.

B.

A compilation error occurs at line n1.

C.

Run…Call…

D.

A compilation error occurs at line n2.

Question 48

Given:

and the code fragment:

What is the result?

Options:

A.

0

B.

A compilation error occurs at line n1.

C.

An Exception is thrown at run time.

D.

2

Question 49

Given the code fragment:

List listVal = Arrays.asList(“Joe”, “Paul”, “Alice”, “Tom”);

System.out.println (

// line n1

);

Which code fragment, when inserted at line n1, enables the code to print the count of string elements whose length is greater than three?

Options:

A.

listVal.stream().filter(x -> x.length()>3).count()

B.

listVal.stream().map(x -> x.length()>3).count()

C.

listVal.stream().peek(x -> x.length()>3).count().get()

D.

listVal.stream().filter(x -> x.length()>3).mapToInt(x -> x).count()

Question 50

Given the code fragments :

and

What is the result?

Options:

A.

TV Price :110 Refrigerator Price :2100

B.

A compilation error occurs.

C.

TV Price :1000 Refrigerator Price :2000

D.

The program prints nothing.

Question 51

Given the code fragment:

Stream> iStr= Stream.of (

Arrays.asList (“1”, “John”),

Arrays.asList (“2”, null)0;

Stream< nInSt = iStr.flatMapToInt ((x) -> x.stream ());

nInSt.forEach (System.out :: print);

What is the result?

Options:

A.

1John2null

B.

12

C.

A NullPointerException is thrown at run time.

D.

A compilation error occurs.

Question 52

Given the code fragment:

Stream files = Files.list(Paths.get(System.getProperty(“user.home”)));

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?

Options:

A.

All files and directories under the home directory are listed along with their attributes.

B.

A compilation error occurs at line n1.

C.

The files in the home directory are listed along with their attributes.

D.

A compilation error occurs at line n2.

Question 53

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?

Options:

A.

0

B.

2

C.

3

D.

4

E.

5

Question 54

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?

Options:

A.

-10

B.

0

C.

An AssertionError is thrown.

D.

A compilation error occurs.

Question 55

Given the code fragment:

List nums = Arrays.asList (10, 20, 8):

System.out.println (

//line n1

);

Which code fragment must be inserted at line n1 to enable the code to print the maximum number in the nums list?

Options:

A.

nums.stream().max(Comparator.comparing(a -> a)).get()

B.

nums.stream().max(Integer : : max).get()

C.

nums.stream().max()

D.

nums.stream().map(a -> a).max()

Question 56

Given:

What is the result?

Options:

A.

Bar HelloFoo Hello

B.

Bar HelloBaz Hello

C.

Baz Hello

D.

A compilation error occurs in the Daze class.

Question 57

Given the code fragment:

List values = Arrays.asList (1, 2, 3);

values.stream ()

.map(n -> n*2)//line n1

.peek(System.out::print)//line n2

.count();

What is the result?

Options:

A.

246

B.

The code produces no output.

C.

A compilation error occurs at line n1.

D.

A compilation error occurs at line n2.

Question 58

Given the code fragment:

UnaryOperator uo1 = s -> s*2;//line n1

List loanValues = Arrays.asList(1000.0, 2000.0);

loanValues.stream()

.filter(lv -> lv >= 1500)

.map(lv -> uo1.apply(lv))//line n2

.forEach(s -> System.out.print(s + “ “));

What is the result?

Options:

A.

4000.0

B.

4000

C.

A compilation error occurs at line n1.

D.

A compilation error occurs at line n2.

Question 59

Given:

Which option fails?

Options:

A.

Foo mark = new Foo (“Steve”, 100);

B.

Foo pair = Foo.twice (“Hello World!”);

C.

Foo percentage = new Foo(“Steve”, 100);

D.

Foo grade = new Foo <> (“John”, “A”);

Question 60

Given the code fragments:

class Employee {

Optional

address;

Employee (Optional

address) {

this.address = address;

}

public Optional

getAddress() { return address; }

}

class Address {

String city = “New York”;

public String getCity { return city: }

public String toString() {

return city;

}

}

and

Address address = null;

Optional

addrs1 = Optional.ofNullable (address);

Employee e1 = new Employee (addrs1);

String eAddress = (addrs1.isPresent()) ? addrs1.get().getCity() : “City Not

available”;

What is the result?

Options:

A.

New York

B.

City Not available

C.

null

D.

A NoSuchElementException is thrown at run time.

Question 61

Given:

Message.properties:

msg = Welcome!

Message_fr_FR.properties:

msg = Bienvenue!

Given the code fragment:

// line n1

Locale.setDefault(locale);

ResourceBundle bundle = ResourceBundle.getBundle("Message");

System.out.print(bundle.getString("msg"));

Which two code fragments, when inserted at line n1 independently, enable to print Bienvenue!?

Options:

A.

Locale locale = new Locale("fr-FR");

B.

Locale locale = Locale.FRANCE;

C.

Locale locale = new Locale ("fr", "FR");

D.

Locale locale = new Locale ("FRANCE", "FRENCH");

E.

Locale locale = Locale.forLanguageTag("fr");

Question 62

Which code fragment is required to load a JDBC 3.0 driver?

Options:

A.

Connection con = Connection.getDriver(“jdbc:xyzdata://localhost:3306/EmployeeDB”);

B.

Class.forName(“org.xyzdata.jdbc.NetworkDriver”);

C.

Connection con = DriverManager.getConnection(“jdbc:xyzdata://localhost:3306/EmployeeDB”);

D.

DriverManager.loadDriver (“org.xyzdata.jdbc.NetworkDriver”);

Page: 1 / 16
Total 208 questions