Summer Special Flat 65% Limited Time Discount offer - Ends in 0d 00h 00m 00s - Coupon code: suredis

Oracle 1z0-809 Java SE 8 Programmer II Exam Practice Test

Demo: 62 questions
Total 208 questions

Java SE 8 Programmer II Questions and Answers

Question 1

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

Options:

A.

At line 1, remove abstract

B.

At line 9, insert super ( );

C.

At line 12, remove public

D.

At line 17, insert super (x);

E.

At line 17, insert super (); super.side = x;

F.

At line 20, use public void area ( ) {

Question 2

Given records from the Player table:

and given the code fragment:

try {

Connection conn = DriverManager.getConnection(URL, username, password);

Statement st= conn.createStatement(

ResultSet.TYPE_SCROLL_SENSITIVE,

ResultSet.CONCUR_UPDATABLE);

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

st.setMaxRows(2);

ResultSet rs = st.getResultSet();

rs.absolute(3);

while (rs.next ()) {

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

}

} catch (SQLException ex) {

System.out.print(“SQLException is thrown.”);

}

Assume that:

The required database driver is configured in the classpath.

The appropriate database is accessible with URL, username, and password.

The SQL query is valid.

What is the result?

Options:

A.

2 Jack3 Sam

B.

The program prints nothing.

C.

3 Sam

D.

SQLException is thrown.

Question 3

Given:

What is the result?

Options:

A.

–catch--finally--dostuff-

B.

–catch-

C.

–finally--catch-

D.

–finally-dostuff--catch-

Question 4

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 5

Given:

interface Doable {

public void doSomething (String s);

}

Which two class definitions compile? (Choose two.)

Options:

A.

public abstract class Task implements Doable {public void doSomethingElse(String s) { }}

B.

public abstract class Work implements Doable {public abstract void doSomething(String s) { }public void doYourThing(Boolean b) { }}

C.

public class Job implements Doable {public void doSomething(Integer i) { }}

D.

public class Action implements Doable {public void doSomething(Integer i) { }public String doThis(Integer j) { }}

E.

public class Do implements Doable {public void doSomething(Integer i) { }public void doSomething(String s) { }public void doThat (String s) { }}

Question 6

Given the code fragment:

BiFunction val = (t1, t2) -> t1 + t2;//line n1

System.out.println(val.apply(10, 10.5));

What is the result?

Options:

A.

20

B.

20.5

C.

A compilation error occurs at line n1.

D.

A compilation error occurs at line n2.

Question 7

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 8

Given the content of /resourses/Message.properties:

welcome1=”Good day!”

and given the code fragment:

Properties prop = new Properties ();

FileInputStream fis = new FileInputStream (“/resources/Message.properties”);

prop.load(fis);

System.out.println(prop.getProperty(“welcome1”));

System.out.println(prop.getProperty(“welcome2”, “Test”));//line n1

System.out.println(prop.getProperty(“welcome3”));

What is the result?

Options:

A.

Good day!Testfollowed by an Exception stack trace

B.

Good day!followed by an Exception stack trace

C.

Good day!Testnull

D.

A compilation error occurs at line n1.

Question 9

For which three objects must a vendor provide implementations in its JDBC driver? (Choose three.)

Options:

A.

Time

B.

Date

C.

Statement

D.

ResultSet

E.

Connection

F.

SQLException

G.

DriverManager

Question 10

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 11

Given the code fragment:

Which code fragment, when inserted at line n1, ensures false is printed?

Options:

A.

boolean b = cs.stream() .findAny() .get() .equals(“Java”);

B.

boolean b = cs.stream() .anyMatch (w -> w.equals (“Java”));

C.

boolean b = cs.stream() .findFirst() .get() .equals(“Java”);

D.

boolean b = cs.stream() .allMatch(w -> w.equals(“Java”));

Question 12

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?

Options:

A.

Read Java ProgrammingView http:/ ebook.com/ebook

B.

Read Java ProgrammingRead http:/ ebook.com/ebook

C.

The EBook.java file fails to compile.

D.

The Test.java file fails to compile.

Question 13

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 14

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?

Options:

A.

static void fly (Consumer bird) {bird :: fly ();}

B.

static void fly (Consumer bird) {bird.accept( ) fly ();}

C.

static void fly (Supplier bird) {bird.get( ) fly ();}

D.

static void fly (Supplier bird) {LOST

Question 15

Given:

and the code fragment:

What is the result?

Options:

A.

0.0

B.

1500.0

C.

A compilation error occurs.

D.

2000.0

Question 16

Given the code fragment:

Which code fragment, when inserted at line n1, enables the code to print /First.txt?

Options:

A.

Path iP = new Paths (“/First.txt”);

B.

Path iP = Paths.toPath (“/First.txt”);

C.

Path iP = new Path (“/First.txt”);

D.

Path iP = Paths.get (“/”, “First.txt”);

Question 17

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?

Options:

A.

Stream stream = Files.list (Paths.get (“/company”));

B.

Stream stream = Files.find(Paths.get (“/company”), 1,(p,b) –> b.isDirectory (), FileVisitOption.FOLLOW_LINKS);

C.

Stream stream = Files.walk (Paths.get (“/company”));

D.

Stream stream = Files.list (Paths.get (“/company/emp”));

Question 18

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 19

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 20

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 stds = Arrays.asList(

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(scr));

What is the result?

Options:

A.

A compilation error occurs.

B.

Java EEJava ME

C.

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

D.

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

Question 21

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?

Options:

A.

An exception is thrown at run time.

B.

2:MyPic.jpeg: MyPic.jpeg

C.

1:Pics:/Pics/ MyPic.jpeg

D.

2:Pics: MyPic.jpeg

Question 22

Given the code fragment:

Map books = new TreeMap<>();

books.put (1007, “A”);

books.put (1002, “C”);

books.put (1001, “B”);

books.put (1003, “B”);

System.out.println (books);

What is the result?

Options:

A.

{1007 = A, 1002 = C, 1001 = B, 1003 = B}

B.

{1001 = B, 1002 = C, 1003 = B, 1007 = A}

C.

{1002 = C, 1003 = B, 1007 = A}

D.

{1007 = A, 1001 = B, 1003 = B, 1002 = C}

Question 23

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

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?

Options:

A.

The method deletes all the .class files in the Projects directory and its subdirectories.

B.

The method deletes the .class files of the Projects directory only.

C.

The method executes and does not make any changes to the Projects directory.

D.

The method throws an IOException.

Question 24

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?

Options:

A.

-10

B.

0

C.

An AssertionError is thrown.

D.

A compilation error occurs.

Question 25

Which statement is true about the DriverManager class?

Options:

A.

It returns an instance of Connection.

B.

It executes SQL statements against the database.

C.

It only queries metadata of the database.

D.

it is written by different vendors for their specific database.

Question 26

Given the code fragments:

interface CourseFilter extends Predicate {

public default boolean test (String str) {

return str.contains (“Java”);

}

}

and

List strs = Arrays.asList(“Java”, “Java EE”, “Embedded Java”);

Predicate cf1 = s - > s.length() > 3;

Predicate cf2 = new CourseFilter() { //line n1

public boolean test (String s) {

return s.startsWith (“Java”);

}

};

long c = strs.stream()

.filter(cf1)

.filter(cf2//line n2

.count();

System.out.println(c);

What is the result?

Options:

A.

2

B.

3

C.

A compilation error occurs at line n1.

D.

A compilation error occurs at line n2.

Question 27

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 28

Given:

class RateOfInterest {

public static void main (String[] args) {

int rateOfInterest = 0;

String accountType = “LOAN”;

switch (accountType) {

case “RD”;

rateOfInterest = 5;

break;

case “FD”;

rateOfInterest = 10;

break;

default:

assert false: “No interest for this account”; //line n1

}

System.out.println (“Rate of interest:” + rateOfInterest);

}

}

and the command:

java –ea RateOfInterest

What is the result?

Options:

A.

Rate of interest: 0

B.

An AssertionError is thrown.

C.

No interest for this account

D.

A compilation error occurs at line n1.

Question 29

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 30

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 emp = Arrays.asList (

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?

Options:

A.

.sorted (Comparator.comparing(Emp::getfName).reserved().thenComparing(Emp::getlName))

B.

.sorted (Comparator.comparing(Emp::getfName).thenComparing(Emp::getlName))

C.

.map(Emp::getfName).sorted(Comparator.reserveOrder())

D.

.map(Emp::getfName).sorted(Comparator.reserveOrder().map(Emp::getlName).reserved

Question 31

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 32

Given the code fragment:

and the information:

    The required database driver is configured in the classpath.

    The appropriate database is accessible with the dbURL, username, and passWord exists.

What is the result?

Options:

A.

A ClassNotFoundException is thrown at runtime.

B.

The program prints nothing.

C.

The program prints Connection Established.

D.

A SQLException is thrown at runtime.

Question 33

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?

Options:

A.

A compilation error occurs in IceCream.

B.

A compilation error occurs in Cake.

C.

A compilation error occurs in Shop.

D.

A compilation error occurs in Bread

E.

All classes compile successfully.

Question 34

Given the code fragment:

Stream files = Files.walk(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 35

Given the code fragment:

Which modification enables the code to print Price 5 New Price 4?

Options:

A.

Replace line n2 with .map (n -> System.out.println (“New Price” + n –1)) and remove line n3

B.

Replace line n2 with .mapToInt (n -> n – 1);

C.

Replace line n1 with .forEach (e -> System.out.print (“Price” + e))

D.

Replace line n3 with .forEach (n -> System.out.println (“New Price” + n));

Question 36

Given:

and this code fragment:

What is the result?

Options:

A.

Open-Close–Exception – 1Open–Close–

B.

Open–Close–Open–Close–

C.

A compilation error occurs at line n1.

D.

Open–Close–Open–

Question 37

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 38

Given:

and the code fragment:

Which definition of the ColorSorter class sorts the blocks list?

Options:

A.

B.

C.

D.

Question 39

Given:

and

Which interface from the java.util.function package should you use to refactor the class Txt?

Options:

A.

Consumer

B.

Predicate

C.

Supplier

D.

Function

Question 40

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;

}

and the code fragment:

List stds = Arrays.asList(

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(scr));

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 41

Given:

Your design requires that:

    fuelLevel of Engine must be greater than zero when the start() method is invoked.

    The code must terminate if fuelLevel of Engine is less than or equal to zero.

Which code fragment should be added at line n1 to express this invariant condition?

Options:

A.

assert (fuelLevel) : “Terminating…”;

B.

assert (fuelLevel > 0) : System.out.println (“Impossible fuel”);

C.

assert fuelLevel < 0: System.exit(0);

D.

assert fuelLevel > 0: “Impossible fuel” ;

Question 42

Given the code fragment:

What is the result?

Options:

A.

Word: why what when

B.

Word: why Word: why what Word: why what when

C.

Word: why Word: what Word: when

D.

Compilation fails at line n1.

Question 43

Which statement is true about java.util.stream.Stream?

Options:

A.

A stream cannot be consumed more than once.

B.

The execution mode of streams can be changed during processing.

C.

Streams are intended to modify the source data.

D.

A parallel stream is always faster than an equivalent sequential stream.

Question 44

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 45

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 46

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 47

Given the code fragment:

What is the result?

Options:

A.

A compilation error occurs at line n1.

B.

courseJava

C.

Javacourse

D.

A compilation error occurs at line n2.

Question 48

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

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

Given:

IntStream stream = IntStream.of (1,2,3);

IntFunction inFu= x -> y -> x*y;//line n1

IntStream newStream = stream.map(inFu.apply(10));//line n2

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

Which modification enables the code fragment to compile?

Options:

A.

Replace line n1 with:IntFunction inFu = x -> y -> x*y;

B.

Replace line n1 with:IntFunction inFu = x -> y -> x*y;

C.

Replace line n1 with:BiFunction inFu = x -> y -> x*y;

D.

Replace line n2 with:IntStream newStream = stream.map(inFu.applyAsInt (10));

Question 50

Given the code fragment:

Path file = Paths.get (“courses.txt”);

// line n1

Assume the courses.txt is accessible.

Which code fragment can be inserted at line n1 to enable the code to print the content of the courses.txt file?

Options:

A.

List fc = Files.list(file);fc.stream().forEach (s -> System.out.println(s));

B.

Stream fc = Files.readAllLines (file);fc.forEach (s - > System.out.println(s));

C.

List fc = Files.readAllLines(file);fc.stream().forEach (s -> System.out.println(s));

D.

Stream fc = Files.list (file);fc.forEach (s -> System.out.println(s));

Question 51

Which two code blocks correctly initialize a Locale variable? (Choose two.)

Options:

A.

Locale loc1 = “UK”;

B.

Locale loc2 = Locale.getInstance(“ru”);

C.

Locale loc3 = Locale.getLocaleFactory(“RU”);

D.

Locale loc4 = Locale.UK;

E.

Locale loc5 = new Locale (“ru”, “RU”);

Question 52

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 53

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 54

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 55

Given the code fragments:

and

What is the result?

Options:

A.

null

B.

A compilation error occurs.

C.

DogCatMouse

D.

[Dog, Cat, Mouse]

Question 56

Which two statements are true about localizing an application? (Choose two.)

Options:

A.

Support for new regional languages does not require recompilation of the code.

B.

Textual elements (messages and GUI labels) are hard-coded in the code.

C.

Language and region-specific programs are created using localized data.

D.

Resource bundle files include data and currency information.

E.

Language codes use lowercase letters and region codes use uppercase letters.

Question 57

Given this code;

Which two are correct after this class is instantiated and tested?

Options:

A.

If the value of j is set to 15, the value of i could be any integer value.

B.

If the value of j is set to 5, the value of i will be 15.

C.

If the value of i is set to 8, the value of j could be any integer value.

D.

If the value of i is set to 5, the value of j will be 1.

E.

If the value of i is set to 6, the value of j will be 18.

F.

If the value of i remains 3, the value of j will remain 9.

Question 58

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 59

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?

Options:

A.

An exception is thrown at runtime.

B.

Compilation fails.

C.

The code prints Error.

D.

The code prints information about Item 110.

Question 60

Given the code fragment:

Which is the valid definition of the Course enum?

Options:

A.

Option A

B.

Option B

C.

Option C

D.

Option D

Question 61

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 62

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

Demo: 62 questions
Total 208 questions