[Sep 22, 2021] Latest 1z0-809 Exam with Accurate Java SE 8 Programmer II PDF Questions
Practice To 1z0-809 - TestsDumps Remarkable Practice On your Java SE 8 Programmer II Exam
NEW QUESTION 34
Given the code fragment:
List<Double> doubles = Arrays.asList (100.12, 200.32);
DoubleFunction funD = d -> d + 100.0;
doubles.stream (). forEach (funD); // line n1
doubles.stream(). forEach(e -> System.out.println(e)); // line n2
What is the result?
- A. 100.12200.32
- B. 200.12300.32
- C. A compilation error occurs at line n2.
- D. A compilation error occurs at line n1.
Answer: C
Explanation:
NEW QUESTION 35
Given the for loop construct:
for ( expr1 ; expr2 ; expr3 ) {
statement;
}
Which two statements are true?
- A. The expression expr1 is optional. it initializes the loop and is evaluated once, as the loop begin.
- B. The expression expr3 must be present. It is evaluated after each iteration through the loop.
- C. When expr2 evaluates to false, the loop terminates. It is evaluated only after each iteration through the loop.
- D. This is not the only valid for loop construct; there exits another form of for loop constructor.
Answer: A,C
Explanation:
The for statement have this forms:
for (init-stmt; condition; next-stmt) {
body
}
There are three clauses in the for statement.
The init-stmt statement is done before the loop is started, usually to initialize an iteration variable.
The condition expression is tested before each time the loop is done. The loop isn't executed if the boolean expression is false (the same as the while loop). The next-stmt statement is done after the body is executed. It typically increments an iteration variable.
NEW QUESTION 36
Given:
public class ScopeTest {
int j, int k;
public static void main(String[] args) {
ew ScopeTest().doStuff(); }
void doStuff() {
nt x = 5;
oStuff2();
System.out.println("x");
}
void doStuff2() {
nt y = 7;
ystem.out.println("y");
or (int z = 0; z < 5; z++) {
ystem.out.println("z");
ystem.out.println("y");
}
Which two items are fields?
- A. x
- B. j
- C. z
- D. k
- E. y
Answer: B,D
NEW QUESTION 37
Given:
Class A { }
Class B { }
Interface X { }
Interface Y { }
Which two definitions of class C are valid?
- A. Class C implements X, Y extends B { }
- B. Class C extends A, B { }
- C. Class C implements Y extends B { }
- D. Class C extends B implements X, Y { }
- E. Class C extends A implements X { }
Answer: D,E
NEW QUESTION 38
The data.doc, data.txt and data.xml files are accessible and contain text.
Given the code fragment:
Stream<Path> 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?
- A. The program prints the content of the three files.
- B. The program prints:
Exception
<<The content of the data.txt file>>
Exception - C. A compilation error occurs at line n1.
- D. The program prints the content of data.txt file.
Answer: A
NEW QUESTION 39
Given the code fragment:
Which statement can be inserted into line n1 to print 1,2; 1,10; 2,20;?
- A. BiConsumer<Integer, Integer, Integer> c = (i, j) ?gt; {System.out.print (i + "," + j+ "; ");};
- B. BiConsumer<Integer, Integer, String> c = (i, j) ?gt; {System.out.print (i + "," + j+ "; ")};
- C. BiConsumer<Integer,Integer> c = (i, j) ->
{System.out.print (i + "," + j+
"; ");}; - D. BiFunction<Integer, Integer, String> c = (i, j) ?gt; {System.out.print (i + "," + j+ "; ")};
Answer: C
NEW QUESTION 40
Given the code fragment:
Which statement is true?
- A. After line 11, one object is eligible for garbage collection.
- B. After line 11, none of the objects are eligible for garbage collection.
- C. After line 11, three objects are eligible for garbage collection.
- D. After line 11, two object are eligible for garbage collection.
Answer: A
NEW QUESTION 41
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 Exception { //line n2
super ride ();
}
}
and the code fragment:
public static void main (String[] args) throws FuelNotAvailException, Exception
{
Vehicle v = new SolarVehicle ();
v.ride();
}
Which modification enables the code fragment to print Happy Journey!?
- A. Replace line n2with private void ride() throws FuelNotAvailException {
- B. Replace line n2with void ride() throws Exception {
- C. Replace line n1with protected void ride() throws Exception {
- D. Replace line n1with public void ride() throws FuelNotAvailException {
Answer: C
NEW QUESTION 42
Given:
public class Canvas implements Drawable {
public void draw () { }
}
public abstract class Board extends Canvas { }
public class Paper extends Canvas {
protected void draw (int color) { }
}
public class Frame extends Canvas implements Drawable {
public void resize () { }
}
public interface Drawable {
public abstract void draw ();
}
Which statement is true?
- A. Boarddoes not compile.
- B. Framedoes not compile.
- C. All classes compile successfully.
- D. Drawabledoes not compile.
- E. Paperdoes not compile.
Answer: C
NEW QUESTION 43
Given the fragments:
Which line causes a compilation error?
- A. Line n4
- B. Line n3
- C. Line n1
- D. Line n2
Answer: C
NEW QUESTION 44
Given the code fragment:
What is the result?
- A. Susan
Allen
[Susan, David] - B. Susan
Susan
[Susan, Allen] - C. David
David
[Susan, Allen] - D. David
Allen
[Susan] - E. Susan
Allen
[David]
Answer: E
NEW QUESTION 45
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?
- A. static void fly (Supplier<Bird> bird) {
bird.get( ) fly ();
} - B. static void fly (Consumer<? extends Bird> bird) { bird.accept( ) fly ();
} - C. static void fly (Consumer<Bird> bird) {
bird :: fly ();
} - D. static void fly (Supplier<? extends Bird> bird) { LOST
Answer: A
Explanation:
Very confusing question. There is no logic in the options.
NEW QUESTION 46
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?
- A. List<String> fc = Files.list(file);
fc.stream().forEach (s - > System.out.println(s)); - B. List<String> fc = readAllLines(file);
fc.stream().forEach (s - > System.out.println(s)); - C. Stream<String> fc = Files.readAllLines (file); fc.forEach (s - > System.out.println(s));
- D. Stream<String> fc = Files.lines (file);
fc.forEach (s - > System.out.println(s));
Answer: D
NEW QUESTION 47
Given the code fragment:
What is the result?
- A. 0
- B.
- C. A compilation error occurs at line n2.
3 - D. A compilation error occurs at line n1.
Answer: C
NEW QUESTION 48
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?
- A. 2:MyPic.jpeg: MyPic.jpeg
- B. 2:Pics: MyPic.jpeg
- C. 1:Pics:/Pics/ MyPic.jpeg
- D. An exception is thrown at run time.
Answer: C
NEW QUESTION 49
Which two reasons should you use interfaces instead of abstract classes? (Choose two.)
- A. You want to share code among several closely related classes.
- B. You want to declare non-static on non-final fields.
- C. You expect that classes that implement your interfaces have many common methods or fields, or require
access modifiers other than public. - D. You want to take advantage of multiple inheritance of type.
- E. You expect that unrelated classes would implement your interfaces.
Answer: D,E
NEW QUESTION 50
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<Country> couList = Arrays.asList (
new Country ("Japan", Country.Continent.ASIA),
new Country ("Italy", Country.Continent.EUROPE),
new Country ("Germany", Country.Continent.EUROPE));
Map<Country.Continent, List<String>> regionNames = couList.stream ()
.collect(Collectors.groupingBy (Country ::getRegion,
Collectors.mapping(Country::getName, Collectors.toList()))));
System.out.println(regionNames);
- A. {EUROPE = [Italy, Germany], ASIA = [Japan]}
- B. {EUROPE = [Germany, Italy], ASIA = [Japan]}
- C. {EUROPE = [Germany], EUROPE = [Italy], ASIA = [Japan]}
- D. {ASIA = [Japan], EUROPE = [Italy, Germany]}
Answer: A
NEW QUESTION 51
Given the definition of the Emp class:
public class Emp
private String eName;
private Integer eAge;
Emp(String eN, Integer eA) {
this.eName = eN;
this.eAge = eA;
}
public Integer getEAge () {return eAge;}
public String getEName () {return eName;}
}
and code fragment:
List<Emp>li = Arrays.asList(new Emp("Sam", 20), New Emp("John", 60), New Emp("Jim", 51));
Predicate<Emp> agVal = s -> s.getEAge() > 50;//line n1
li = li.stream().filter(agVal).collect(Collectors.toList());
Stream<String> names = li.stream()map.(Emp::getEName);//line n2
names.forEach(n -> System.out.print(n + " "));
What is the result?
- A. John Jim
- B. Sam John Jim
- C. A compilation error occurs at line n1.
- D. A compilation error occurs at line n2.
Answer: A
NEW QUESTION 52
Given the code fragment:
BiFunction<Integer, Double, Integer> val = (t1, t2) -> t1 + t2; //line n1
System.out.println(val.apply(10, 10.5));
What is the result?
- A. 20.5
- B. A compilation error occurs at line n1.
- C. 0
- D. A compilation error occurs at line n2.
Answer: B
NEW QUESTION 53
......
Exam Questions and Answers for 1z0-809 Study Guide Questions and Answers!: https://www.testsdumps.com/1z0-809_real-exam-dumps.html
Practice To 1z0-809 - TestsDumps Remarkable Practice On your Java SE 8 Programmer II Exam: https://drive.google.com/open?id=1KHk2cBBZ3wnJYCoKXsozH4dxCbruj74B
