Java Magazine, September/October 2016
ORACLE COM JAVAMAGAZINE SEPTEMBER OCTOBER 2016 59 fix this Which is true Choose one a The code reliably returns the correct sum of the numbers as it is b The code would reliably return the correct sum of the numbers if the body of the method were changed to this int total 0 is peek v total 0 v forEach System out println return total 0 c The code would reliably return the correct sum of the numbers if the type of total were changed to Integer d The code would reliably return the correct sum of the numbers if the call to parallel were moved after the call to peek v total v e The code would reliably return the correct sum of the numbers if the type of total were changed to LongAdder and if the lambda in peek were changed accordingly Question 4 Given this code public static void main String args ExecutorService es Executors newFixedThreadPool 2 Callable String job Thread sleep 5000 line n1 return Hello es submit job es submit job Future String handle es submit job line n2 System out println submitted String message handle get line n3 System out println message System exit 0 Which is true Choose one a Compilation fails due to an error at line n1 b Compilation fails due to an error at line n3 c The program throws a RejectedExecutionException because there are no available threads at line n2 d The program immediately prints submitted and then after a 10 second pause it prints Hello e The program pauses five seconds then prints submitted and then after a further five second pause it prints Hello Question 5 Given that the current working directory of the following program contains this tree one a t1 txt b two c t2 txt where one two a b and c are directories and the program code is this public static void main String args throws Throwable Files find Paths get 1 p a a isDirectory forEach System out println What is the output Choose one a b one two
You must have JavaScript enabled to view digital editions.