Free Oracle 1Z0-809 Exam Questions (page: 5)

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 ()) {
recDelete (aFile.getAbsolutePath ());
} else {
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?

  1. The method deletes all the .class files in the Projects directory and its subdirectories.
  2. The method deletes the .class files of the Projects directory only.
  3. The method executes and does not make any changes to the Projects directory.
  4. The method throws an IOException.

Answer(s): A



Given the code fragments:
4. void doStuff() throws ArithmeticException, NumberFormatException, Exception {
5. if (Math.random() >-1 throw new Exception (“Try again”);
6. }

and

24. try {
25. doStuff ( ):
26. } catch (ArithmeticException | NumberFormatException | Exception e) {
27. System.out.println (e.getMessage()); }
28. catch (Exception e) {
29. System.out.println (e.getMessage()); }
30. }

Which modification enables the code to print Try again?

  1. Comment the lines 28, 29 and 30.
  2. Replace line 26 with:
    } catch (Exception | ArithmeticException | NumberFormatException e) {
  3. Replace line 26 with:
    } catch (ArithmeticException | NumberFormatException e) {
  4. Replace line 27 with:
    throw e;

Answer(s): C



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

  1. {EUROPE = [Italy, Germany], ASIA = [Japan]}
  2. {ASIA = [Japan], EUROPE = [Italy, Germany]}
  3. {EUROPE = [Germany, Italy], ASIA = [Japan]}
  4. {EUROPE = [Germany], EUROPE = [Italy], ASIA = [Japan]}

Answer(s): B



Given the code fragment:
Map<Integer, String> 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?

  1. {1007 = A, 1002 = C, 1001 = B, 1003 = B}
  2. {1001 = B, 1002 = C, 1003 = B, 1007 = A}
  3. {1002 = C, 1003 = B, 1007 = A}
  4. {1007 = A, 1001 = B, 1003 = B, 1002 = C}

Answer(s): B


Reference:

TreeMap inherits SortedMap and automatically sorts the element's key



Viewing page 5 of 42



Post your Comments and Discuss Oracle 1Z0-809 exam prep with other Community members:

1Z0-809 Exam Discussions & Posts