Java Magazine, September/October 2016
ORACLE COM JAVAMAGAZINE SEPTEMBER OCTOBER 2016 64 fix this This means that the only elements that will even be considered are the two directories one and two and the file t2 txt The next argument is a BiPredicate Path BasicFile Attributes This is called for every path element that is seen to determine whether to include that element in the output Its a predicate so its probably no surprise that if this returns false the item will be removed from the output stream Nothing in the question tells you that the arguments are a Path and a BasicFileAttributes but because no options include does not compile its a safe assumption that the second lambda argument a in this case actually does have a method isDirectory From that you can deduce that only directories will be passed into the output and now the situation goes from three path elements being seen one two and t2 txt to only the two directories moving to the output Now you know that the correct answer is option B Its interesting that this find method returns a stream Its lazy like all streams are supposed to be though presumably it has a decent size buffer at the file system interface This actually raises another observation that the question ignores Stream objects implement AutoCloseable and while in memory streams dont really need to be closed those that are attached to operating system resources other than memory for example files network and database connections should be closed This can be a subtle but important issue if youre writing a method that receives a stream as an argument if you dont know how the stream was opened can you assume that it doesnt need to be closed In such situations perhaps you should give the stream the protection of the try with resources construct article Simon Roberts joined Sun Microsystems in time to teach Suns first Java classes in the UK He created the Sun Certified Java Programmer and Sun Certified Java Developer exams He wrote several Java certification guides and is currently a freelance educator who teaches at many large companies user groups THE DANISH JUG The only Danish Java user group JUG Javagruppen was founded in December 1996 The first oficial meeting was held in January 1997 and was initiated with these words Never before in computer history has a new technology been gaining support the way Java has Maybe it is because there is a real need for an alternative to C and Visual Basic During its first years the JUG functioned as a special interest group for companies working with Java in Denmark and in 2004 it was reformed as a new legal entity with an elected board and yearly general assemblies Members of the JUG pay a yearly fee Until this year only companies could become members and that membership covered individuals or all employees Recently it was decided that private individuals could become members for a reduced fee and students could join for free Today the group consists of about 80 paying members split evenly between individuals and company memberships The JUG organizes 6 to 10 meetings every year divided between Copenhagen and Aarhus The JUG hosts an annual Java developer conference JDK IO This years conference takes place in Copenhagen in the middle of September at the Royal National Library Javagruppen has for many years organized programming for kids and has joined the Devoxx4Kids initiative Find out more about the JUG by following it on Facebook and Twitter
You must have JavaScript enabled to view digital editions.