Java streams are a feature introduced in Java 8 that allows developers to perform functional-style operations on collections of data. Streams are designed to make it easier to write more concise, declarative code for manipulating collections, and to take advantage of multi-core processors for improved performance.
java
Intro to Reactor, Mono, and Flux
This entry gives a quick overview of reactor project, mono, flux, error handling, defer, inner mono, and common pitfalls of using reactor. You may find this entry helpful as well, Non-Blocking vs Reactive
Java Streams Code Snippets
What is a Java Stream?
Java Stream is a sequence of elements supporting the sequential and parallel aggregate operation. This example shows an aggregate operation using Stream and IntStream
int sum = widgets.stream() .filter(w -> w.getColor() == RED) .mapToInt(w -> w.getWeight()) .sum();
In this example (from Oracle Stream doc), widgets
is a Collection<Widget>. A stream of Widget
objects was created via Collection.stream()
, filter it to product a stream containing only the red widgets, and then transform it into a stream of int values representing the weight of each red widget. Finally this stream is summed to produce a total weight.
This post lists Java Streams code snippets that I find very useful
Lombok Tips
What is Lombok?
In their own word,
Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java. Never write another getter or equals method again, with one annotation your class has a fully featured builder, Automate your logging variables, and much more
Why Use Lombok
- Reduce boilerplate code
- Increase readability
- Reduce work for unit test code coverage
When to NOT use Lombok?
- More complex entity classes (non-POJO classes)
How to Update Eclipse Software on Linux behind proxy
To update eclipse software on Linux behind proxy is a bit tricky but doable and here is how: 1) Find the proxy server’s host name and your account’s authentication info 2) Open the network connection by “Windows”->”Preferences”-> “General”->”Network Connection”, select “manual” and enter the proxy information. Below is a screenshot of my setup:
Update to JDK 8 on Mac OS
Java 8 (1.8.11 at the time of the writing) is the latest Java version. It was released in March this year and contain various major updates, including the long-waited lambda support. This blog described how to update to JDK 8 on Mac OS and also to check the lambda support with a simple app.
Java with Greenfoot Lesson 1: Hello Wombats!
If you are familiar with Scratch and would like to learn more on programming. Java with Greenfoot is a great choice.
In this lesson, we will test the water by looking at a sample Greenfoot project called “wombats”.
Java with Greenfoot Lesson 2: Tic-Tac-Toe Game Part I
In this lesson, we will create a Tic-Tac-Toe game board and add game pieces to it.
Java with Greenfoot Lesson 3: Tic-Tac-Toe Game Part II
In the last lesson (Lesson 2), we created the Tic-Tac-Toe Board and GameBall classes. We also added GameBall objects to the Board object. In this lesson, we will add a Player class such that a Player object interacts with GameBall objects in a meaningful way.
Java with Greenfoot Lesson4: Tic-Tac-Toe Game Part III
In this lesson, we will make the Board class check the game progress and stop the game once someone has won. I will then introduce the concept of Java Arrays. We will add code to constantly check whether three game balls of the same color has lined up and to mark those winning game balls.