1z0-809 Exam Question 26
Given the code fragment:
Path p1 = Paths.get("/Pics/MyPic.jpeg");
System.out.println (p1.getNameCount() +
" :" + p1.getName(1) +
" :" + p1.getFileName());
Assume that the Picsdirectory does NOT exist.
What is the result?
Path p1 = Paths.get("/Pics/MyPic.jpeg");
System.out.println (p1.getNameCount() +
" :" + p1.getName(1) +
" :" + p1.getFileName());
Assume that the Picsdirectory does NOT exist.
What is the result?
1z0-809 Exam Question 27
Given the definition of the Empclass:
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?
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?
1z0-809 Exam Question 28
Given the code fragment:
Stream<Path> 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?
Stream<Path> 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?
1z0-809 Exam Question 29
Given:
public class Foo<K, V> {
private K key;
private V value;
public Foo (K key, V value) (this.key = key; this value = value;)
public static <T> Foo<T, T> twice (T value) (return new Foo<T, T>
(value, value); )
public K getKey () (return key;)
public V getValue () (return value;)
}
Which option fails?
public class Foo<K, V> {
private K key;
private V value;
public Foo (K key, V value) (this.key = key; this value = value;)
public static <T> Foo<T, T> twice (T value) (return new Foo<T, T>
(value, value); )
public K getKey () (return key;)
public V getValue () (return value;)
}
Which option fails?
1z0-809 Exam Question 30
Given the code fragments:
public class Book implements Comparator<Book> {
String name;
double price;
public Book () {}
public Book(String name, double price) {
this.name = name;
this.price = price;
}
public int compare(Book b1, Book b2) {
return b1.name.compareTo(b2.name);
}
public String toString() {
return name + ":" + price;
}
}
and
List<Book>books = Arrays.asList (new Book ("Beginning with Java", 2), new book
( "A
Guide to Java Tour", 3));
Collections.sort(books, new Book());
System.out.print(books);
What is the result?
public class Book implements Comparator<Book> {
String name;
double price;
public Book () {}
public Book(String name, double price) {
this.name = name;
this.price = price;
}
public int compare(Book b1, Book b2) {
return b1.name.compareTo(b2.name);
}
public String toString() {
return name + ":" + price;
}
}
and
List<Book>books = Arrays.asList (new Book ("Beginning with Java", 2), new book
( "A
Guide to Java Tour", 3));
Collections.sort(books, new Book());
System.out.print(books);
What is the result?