What is the result?

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 () < 6) {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 = […]

Read More

What is the result?

Given the code fragment:List<String> colors = Arrays.asList(“red”, “green”, “yellow”);Predicate<String> test = n – > {System.out.println(“Searching…”);return n.contains(“red”);};colors.stream().filter(c -> c.length() > 3).allMatch(test);What is the result? A. Searching… B. Searching… Searching… C. Searching… Searching… Searching… D. A compilation error occurs. Show Answer

Read More

What is the result?

Given the code fragment:Path path1 = Paths.get(“/app/./sys/”);Path res1 = path1.resolve(“log”);Path path2 = Paths.get(“/server/exe/”);Path res1 = path1.resolve(“/readme/”);System.out.println(res1);System.out.println(res2);What is the result? 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 Show Answer

Read More

What is the result?

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 n1System.out.println(“Travel time is” + hrs + “hours”);What is the result? A. Travel time is 4 hours B. Travel time is 6 hours C. Travel time is […]

Read More

What is the result?

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? A. Read Java Programming View […]

Read More

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

Given the code fragment:List<Integer> list1 = Arrays.asList(10, 20);List<Integer> list2 = Arrays.asList(15, 30);//line n1Which code fragment, when inserted at line n1, prints 10 20 15 30? 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 […]

Read More

Which two class definitions compile?

Given:interface Doable {public void doSomething (String s);}Which two class definitions compile? 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 { […]

Read More

Which statement is true?

Given that /green.txt and /colors/yellow.txt are accessible, and the code fragment:Path source = Paths.get(“/green.txt);Path target = Paths.get(“/colors/yellow.txt);Files.move(source, target, StandardCopyOption.ATOMIC_MOVE);Files.delete(source);Which statement is true? A. The green.txt file content is replaced by the yellow.txt file content and the yellow.txt file is deleted. B. The yellow.txt file content is replaced by the green.txt file content and an exception […]

Read More

Which should be inserted at line n1 to print Java-Oracle DB-J2EE-?

Given the code fragments:class TechName {String techName;TechName (String techName) {this.techName=techName;}}andList<TechName> tech = Arrays.asList (new TechName(“Java-“),new TechName(“Oracle DB-“),new TechName(“J2EE-“));Stream<TechName> stre = tech.stream();//line n1Which should be inserted at line n1 to print Java-Oracle DB-J2EE-? A. stre.forEach(System.out::print); B. stre.map(a-> a.techName).forEach(System.out::print); C. stre.map(a-> a).forEachOrdered(System.out::print); D. stre.forEachOrdered(System.out::print); Show Answer

Read More

Which code fragment should be inserted at line n1 to enable the code to print Rat Cat Lion Tiger?

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 n1for (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? […]

Read More