Test 21 - Free Java SE 25 certification Mock test - Exam Code 1Z0-831-Oracle certified Java SE 25 Professional
Streams power a huge amount of modern Java and this free mock test for the Oracle 1Z0-831 exam is all about getting you up and running with the fundamentals. It looks at creating streams, intermediate and terminal operations, lazy evaluation and primitive streams, all within the Streams and Lambda objective of the Java SE 25 Developer certification.
You start with how streams are created: from collections via the stream method, from arrays via Arrays.stream, from values via Stream.of and from generators via iterate and generate. The questions make it very clear that a stream can be consumed only once and that attempting to use it again will result in an IllegalStateException. You'll also see that a pipeline with no terminal operation does absolutely nothing (a point that crops up in a number of printed output puzzles).
Intermediate ops get a lot of practice. You'll be using filter, map, flatMap, distinct, sorted, limit, skip, peek, takeWhile and dropWhile and you'll have to work out the order in which the elements flow. As the streams are lazy and process the elements one at a time through the entire pipeline the sequence that gets printed out by the peek calls is often very different from what the novice would expect. You'll be very careful to trace these. You'll also be looking at short circuiting with limit and findFirst where the later elements are never actually processed.
Terminal operations are the next lot: forEach, collect, reduce, count, min, max, anyMatch, allMatch, noneMatch, findFirst and findAny. You'll look at what each of these returns (with a particular focus on the Optional results) and learn how to use orElse, orElseGet, orElseThrow, ifPresent and ifPresentOrElse appropriately. The items also test the various reduce variants (with identity, with no identity and with a combiner).
Primitive streams form a big section. IntStream, LongStream and DoubleStream provide range, rangeClosed, sum, average, summaryStatistics, boxed and mapToObj and you'll certainly be able to guess which of those return the primitives (OptionalInt or OptionalDouble). The conversions between object and primitive streams via mapToInt and boxed are going to be very common.
Lambda syntax is all over the place, including effective final capture and method references. Each explanation walks you through the pipeline step by step. There's a question that poses a pipeline which appears to be modifying the source list in forEach or peek. That's not allowed (it's discouraged and could throw an exception) so you need to be able to spot that. The trick is to read the pipeline as a sequence of small, independent stages. That makes the puzzles much easier. Do the test, go through any item where the order of output was surprising and re-write that pipeline as a plain loop to check you've got it.
