Update: Java 11 Practice Tests

Jeanne and I know many of our readers are anxiously awaiting their copy of our new Java OCP 11 Practice Test Book for the 1Z0-819 Exam, originally expected out this month. The good news is we finished the manuscript a few months ago, so the book is done! The bad news is, the publishing and printing process has been slower than expected given everything going on in the world.

We now expect the book to be available in late January/early February. Believe us, no one is more anxious for this book than us! If you purchase the book from Amazon or other resellers, it will ship as soon as it is available!

Oh, and a big thanks to all our readers this year, whose feedback and support has kept us going in these strange times!

New Zoom self-selecting breakout rooms

I live the new Zoom feature to be able to switch between breakout rooms. You have to be on the latest zoom and the feature has to be enabled for your meeting.

After clicking breakout rooms at the bottom, you see the choices along with who is in each room. The trick is mousing over the number. If I mouse over “5”, it turns into the word join.

You can join a breakout from either the main room or another breakout. And you can always go back to the main room by clicking “leave breakout room.”

This is far better than my hack of joining as my computer, iPad and iPhone and switching physical devices. It also lets the team know which session I am actually paying attention too!

Multi statement lambda and for each anti patterns

When I do a code review of lambda/stream code, I am immediately suspicious of two things – block statement lambdas and forEach().

What’s wrong with this? It’s functional programming right?

List<Integer> list = Arrays.asList(1,2,3,4,5,6,7,8,9,10);
		
AtomicInteger sum = new AtomicInteger();
List<Integer> odds = new ArrayList<>();
List<Integer> evens = new ArrayList<>();
		
list.forEach(n -> {
	sum.addAndGet(n);
	if (n % 2 == 0) {
		evens.add(n);
	} else {
		odds.add(n);
	}
});
		
odds.forEach(System.out::println);
System.out.println();
evens.forEach(System.out::println);
System.out.println();
System.out.println(sum);

Well? Not really. It does have a lambda. It doesn’t have a stream, but that’s easy enough to fix: list.stream().forEach(…).

All better? No. Just because you are using a stream doesn’t mean you are doing functional programming. I would much rather see this code as:

List<Integer> list = Arrays.asList(1,2,3,4,5,6,7,8,9,10);
		
		
list.stream()
   .filter(x -> x % 2 == 1)
   .forEach(System.out::println);

System.out.println();

list.stream()
   .filter(x -> x % 2 == 0)
   .forEach(System.out::println);

System.out.println();

list.stream()
   .mapToInt(x -> x)
   .sum();

Yes, I’m still using forEach(). But now I’m using it for one purpose (printing) rather than sticking logic in it.

Whenever I see a forEach() or lambda with more than one statement, my first thought is “could this be clearer or more functional.” Often the answer is yes. Filter(), map() and collect() are you friends.

And if I did need that List?

list.stream()
   .filter(x -> x % 2 == 1)
   .collect(Collectors.toList());